You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Erinc Arikan <er...@gmail.com> on 2009/09/18 23:19:15 UTC
Where to handle byte unstuffing?
Hi Everybody;
I hope my question won't seem so trivial, I am pretty new to Mina, but I am
making some progress, I managed to write my own protocolfilter for my byte
stream TCP protocol.
Here is some information about my protocol details.
Every message starts with a certain character, and end with a certain
character. Every message contains some fixed length fields and variable
length fields. For each variable length field I have another dedicated field
that tells the length of the field in question. Before clients send the
message to the socket on the server, they stuff everything between message
start and message end, to prevent any existence of the special
bytes(beginning byte and ending byte), they simply insert a constant byte
before the special character and add the constant byte to the special byte
and place it to the next location in the byte stream.
So server has to go through the complete message and unstuff these cases, by
doing the reverse operation.
That operation would be so easy to accomplish if everything is guaranteed to
be received in one piece. But since there might be fragmentation, I am not
quite sure if I will be able to decode my object inside doDecode method.
One Possible solution is looping through the message until seeing the end
byte and passing that to somewhere else to process unstuffing. Because of
stuffing I am guaranteed to have one end and one beginning bytes in a
message, so that will do it.
I am wondering if there might be a better solution by implementing something
inside Mina's functionality?
Thanks in advance
Erinc
Re: Where to handle byte unstuffing?
Posted by Ashish <pa...@gmail.com>.
On Sat, Sep 19, 2009 at 2:49 AM, Erinc Arikan <er...@gmail.com> wrote:
> Hi Everybody;
>
> I hope my question won't seem so trivial, I am pretty new to Mina, but I am
> making some progress, I managed to write my own protocolfilter for my byte
> stream TCP protocol.
>
> Here is some information about my protocol details.
>
> Every message starts with a certain character, and end with a certain
> character. Every message contains some fixed length fields and variable
> length fields. For each variable length field I have another dedicated field
> that tells the length of the field in question. Before clients send the
> message to the socket on the server, they stuff everything between message
> start and message end, to prevent any existence of the special
> bytes(beginning byte and ending byte), they simply insert a constant byte
> before the special character and add the constant byte to the special byte
> and place it to the next location in the byte stream.
>
> So server has to go through the complete message and unstuff these cases, by
> doing the reverse operation.
>
> That operation would be so easy to accomplish if everything is guaranteed to
> be received in one piece. But since there might be fragmentation, I am not
> quite sure if I will be able to decode my object inside doDecode method.
>
> One Possible solution is looping through the message until seeing the end
> byte and passing that to somewhere else to process unstuffing. Because of
> stuffing I am guaranteed to have one end and one beginning bytes in a
> message, so that will do it.
>
> I am wondering if there might be a better solution by implementing something
> inside Mina's functionality?
>
CumulativeProtocolDecoder is the right choice for you.
There are couple of decoder implementations that you can refer to
http://mina.apache.org/codec-repository.html
--
thanks
ashish
Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal