Le 30/06/15 12:41, Nikunj Patel a écrit :
> Dear Sir,
>
> I have developed network application which communicate to server. Now some
> time due to TCP queuing, I got multiple message at same time. 

Which is perfectly normal.

> To handle
> that I write the decoder which work for fine for first message but for
> second message it not identified it. My message structure is 2 Byte in hex
> Message length + message body. I am attaching decoder here with. I want
> split all message base on its length while receiving multiple message.
The attachement didn't make it.

Anyway, it's your decoder's task to iterate through everything it has
received, and to decode the messages.

Assuming your messages are encoded using a length first, a body next,
you should first decode the length, and then read the following bytes up
to length. You also have to take care of fragmentation : there is no
guarantee that a message will be fully received. When you have been able
to read the full length, then if you have some remaining bytes in the
incoming buffer, then you have to iterate.

Frgamenation handling : the received data could not contain the expected
length (and that's not only true for the data, but for the 'length'
itself, if it's not a byte). You have to keep an accumulator in your
session to deal with that. You can have a look at the
CumulativeProtocolDecoder code which does that.
(http://grepcode.com/file/repo1.maven.org/maven2/org.apache.mina/mina-core/1.1.6/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java)




Reply via email to