Message to Netty Server sometimes gets lost

"이희승 (Trustin Lee)" trustin at gmail.com
Mon Jul 12 04:05:02 EDT 2010


Hi Michael,

On 07/11/2010 09:38 PM, NettyMW wrote:
> 
> I have implemented a Java Server with netty which communicates with a Java
> TCP Socket Client. 
> The Server sends some information to a Java TCP Socket Client and reads
> StatusCodes from this Client. After sending the statuscode with:
> 
> outputStream.write(satuscode);
> outputStream.flush();
> 
> The Client disconnects. 
> 
> The Problem is, sometimes Statuscodes get lost - the Statuscode never enters
> the StatusCodeDecoder of the Server. When the Client doesn't perform the
> disconnection but the server after receiving a statuscode, everything works
> fine. 
> 1. Question: is this normal behaviour? Or do i have a synchronisation
> Problem or something?

Normally, the server should receive the status code.

> The course of actions:
> - Server starts. A XHandler (not sharable) is added to the server's pipeline
> (pipeline.addLast). Question 2.: This means for every connection a new
> handler is added to the pipeline?

It depends on how you wrote your ChannelPipelineFactory.  If XHanlder is
unsharable, you should create a new instance every time
ChannelPipelineFactory.getPipeline() is called.

> - Java Client connects and sends some Binary Data.
> - On channelOpen the XHandler adds a DecoderX to the pipeline
> (pipeline.addFirst)
> - XDecoder accepts the Data from the Client and depending on the received
> data, a YDecoder is added after XDecoder. Afterwards XDecoder is removed
> from the pipeline and the Data is handed over to the YDecoder
> - YDecoder accepts further Data and returns a JavaObject
> - On messageReceived the XHandler gets the JavaObject. Then XHandler adds a
> new DecoderZ to the pipeline (atFirst) and sends some Data to the Client
> - The Client reads the Data and sends a StatusCode to the Server then the
> client disconnects
> - The ZDecoder (StatusCodeDecoder) should accept the StatusCode but sometime
> no statuscode is received?

When removing a decoder, you must make sure all data in its internal
buffer has been consumed.  If there's some unhandled data in the
internal buffer and you removed the decoder, you will lose the data.

I guess the status code has been received into the decoder's internal
buffer but not decoded due to removal.

> Further Questions: 
> 3. when a new Connection is opened the old Decoder are removed from the
> Pipeline? Or are there more and more XHandlers and Decoders in the
> Pipeline??

A new pipeline is created for a new connection.  Pipelines are never shared.

> 4. Do i have to synchronize the decode Messages of the Decoders or something
> else?

No, unless you call it from the threads that Netty doesn't run.

HTH,
Trustin

-- 
what we call human nature in actuality is human habit
http://gleamynode.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 293 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100712/b71f08e9/attachment-0001.bin 


More information about the netty-users mailing list