My apologies--I mistyped.
> if (receivedEndSequence && !ioBuffer.hasRemaining()) { << I
> don't have any more remaining.
> //logging
> out.write(fullMessage);
> return true;
> }
To be honest, I am not sold that I need this at all. I put it in place over a
generic TextLineEncoder to see if maybe my connection closing problem was
related to a specific character sequence or to a break because of buffer size
or something like that.
Is there anything else that I can try? Is there any control sequences that
might be coming up? I implemented the KnockKnock server functionality with
MINA and was convinced that it could do the bi-directional communication on a
single connection that I needed. That works fine. I used the same code in
this project and the connection completely fails--apparently without any sort
of recourse since no errors are thrown.
Yours in frustration.
-----Original Message-----
From: Emmanuel Lécharny [mailto:[email protected]]
Sent: Tuesday, May 14, 2013 4:01 AM
To: [email protected]
Subject: Re: Help with NioSocketConnector
A few comments inline...
Le 5/13/13 10:29 PM, Whitener, Winona T. a écrit :
> Please forgive wonky capitals. I'm having to type this from computer to
> computer. No exceptions are being recorded. No exceptions are being caught.
>
> It's definitely not the prettiest code and needs cleaning, but I am unable to
> track down why the connection is closing here.
>
> Thank you for your help.
>
> public class CodecFactory extends TextLineEncoder implements
> ProtocolCodecFactory {
> public static String EOM = "//endmsg//";
> public static String BOM = "//stmsg//";
>
> public ProtocolEncoder getEncoder(IoSession ioSession) {
> return (ProtocolEncoder) new CustomEncoder();
> }
>
> public ProtocolDecoder getDecoder(IoSession ioSession) {
> return (ProtocolDecoder) new CustomDecoder();
> }
> }
>
> Public class CustomDecoder extends CumulativeProtocolDecoder { ///
> Public Boolean doDecode(<args>) throws Exception {
> Try {
> Int startPosition = ioBuffer.position();
> Boolean receivedEndSequence = false;
>
> StringBuffer buffer = new StringBuffer();
Here, I would simply convert the full buffer to a String, instead of
accumulating the bytes one by one.
> while (ioBuffer.hasRemaining()) {
> byte by = ioBuffer.get();
> buffer.append((char)b);
> if (buffer.toString().endWith(CodecFactory.EOM)) {
> receivedEndSequence = true;
> }
> }
// Now, check if you found the end sequence
One question : why are you testing if you still have some bytes in your buffer ?
> if (receivedEndSequence && ioBuffer.hasRemaining()) {
> //logging
> out.write(fullMessage);
> return true;
> }
> }
> Catch (Exception e) {
> //logging
> }
> }
> }
All in all, I don't think that usng a CummulativeProtocolDecoder is helpful. I
would rather process the data as they come, dealing with fragmentation by hand.
You have more control.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com