On Fri, May 15, 2009 at 4:38 PM, Erinc Arikan <[email protected]> wrote:

> Thanks Emmanuel;
>
> Is this issue related to Nagle's Algorithm?


No.


>
> Do I have to use
>
> ((SocketSessionConfig) connector.getSessionConfig()).setTcpNoDelay(false)


No, certainly not !


>
>
> to ensure that I will receive only one complete message


You can't have such a guarantee. There is no way you can get it.



> given that I
> implement MessageDecoder correctly, but I feel like setting tcpnodelay
> false
> will negatively affect the performance. Is there any way that I can just
> prevent partial messages in the PDU?


No.


> I am happy receiving multiple messages
> but I want to be able to deal with partial messages somehow instead of
> discarding them.


Just use the cumulative decoder, but you will have to deal with message's
size. This is the frontier between MINA and your implementation on top of
it. MINA knows nothing about your messages, and your protocol. So you have
to code your codec in a way it handles all the possible messages, even if
they are fragmented.

The idea is to check if the buffer contains enough bytes to decode a
complete message, assuming you can determinate the message size, of course,
and if so, call the decoder, otherwise do nothing (the buffer is stored in
the session by the extended class).If you have more than one message in the
buffer, you will have to call the decoder until you don't have enough bytes
remaining in the buffer. Last, not least, if you can deal with messages of
different sizes, you have to determinate which kind of message you are
dealing with before calling the decoder.

In any case, MINA helps you to focus on this part of the code, alleviating
the pain about the management of sockets, connection, etc.But it's your task
to handle the protocol !

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Reply via email to