Le 27/01/15 17:34, Marek Sedlak a écrit :
> Hello,
>
> I have been trying to implement a simple http server. Firstly using
> TextLineCodecFactory, but it became little useles for parsing binary data
> comming in request.
> What I decided to do, is basically TCP server, and reading requests
> manually. All I need to do is to get byte array data of request.
>
> in method messageReceived(Object o) the data come, but sometimes (usually
> on POST/PATCH requests) the body comes in another call of this method.
>
> Then I dont know when the data is complete. Can you please guide me? I am
> using MINA 2.0.9.

This is typically what happen with TCP fragmentation.

The data may arrive chunk by chunk. You can even imagine receiving them
one byte by one byte...

So you have to take care of such a fragmentation, which is not exactly
simple with a protocol like HTTP, where you have no information
whatsoever about the size of what you are going to receive.

The best possible solution would be to decode what you get, excpecting
it's not going to be cut in the middle. If you don't have anough data,
then you have to suspend the decoding, and wait for more data...


Reply via email to