Erinc Arikan wrote:
Thanks for the response.
I actually figured out my problem I was stuffing and unstuffing data in my
pojo, It looks like that's the problem I can't believe how I totally forgot
about that.
Cool !
As you have mentioned the following code for my decoder will work ok for LAN
scenarios. It will be problematic if I receive 78 bytes one by one. How can
I handle that scenario if message reaches server in parts? There can be many
fragmented messages that might be coming from different clients. How can my
server figure out which message belongs to which historical message and
merge them correctly to make a complete message? How can the following code
be improved? Is there a working example that I can take a look at?
First, every connection is associated with a session in MINA, so if a fragment is received, it belongs to a session. Now, the only thing you have to do is to accumulate the message in a temporary buffer, and store this buffer within this session until the message is completed.

Be aware that you not only can receive a fragment, but may be - depending on your protocol - more than one message in the same PDU (ie you may receive 200 bytes, 2 times 78 bytes plus some more bytes associated with another message). You have to deal with that.

If the protocol is a text based one, you may have a look to the documentation :

http://mina.apache.org/handling-packet-fragementation.html

The tutorial explain how to handle fragmented messages, using a class extending the CumulativeProtocolDecoder class.

Hope it helps...

--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to