How to reliable and efficiently implement a string protocol

Sébastien Pierre sebastien.pierre at gmail.com
Wed Nov 3 10:36:29 EDT 2010


Hmm, that's what I thought but I think I'm using it wrong -- I think the
client should use an encoder rather than a decoder, and that the decoder
should go in the server.

Thanks anyway :)

 -- Sébastien

2010/11/2 Christian Migowski <chrismfwrd at gmail.com>

> Hi,
>
> the use of the DelimiterbasedFrameDecoder ensures that your
> messageReceived method only gets complete "frames", that is lines in
> your case. So you don't need to check and buffer in your
> messagereceived method. Also, but I am not 100% sure on this, I would
> assume that the framedecoder removes the delimiters from the received
> data, so that your code would not work very well anyway.
>
> regards,
> christian!
>
>
>
> 2010/11/2 Sébastien Pierre <sebastien.pierre at gmail.com>:
> > Hi !
> > I've been using Netty to implement a very simple text-based protocol for
> a
> > log service, where messages are UTF-8 strings like this:
> > <LOG_FILE_PATH>:<JSON_ENCODED_MESSAGE_DATA>\n
> > For instance
> > hello/world.log:"Hello, World"\n
> > would append "Hello, World" to the hello/world.log file.
> > The problem I have is that it seems that some messages get interwoven,
> > basically just as if the server considered two messages as being part of
> the
> > same one, and intermixing both. My problem is then: how do I ensure that
> > each message is reliably sent, and that the server does not "interweaves"
> > received messages.
> > The server is implemented using a ChannelPipelineCoverage("one")
> > SimpleChannelUpstreamHandler. The message aggregation happens in
> > messageReceived, which works like this:
> > if message contains "\n"
> >    write(buffer)
> > else
> >   buffer append (message)
> > end
> >
> > with a pipeline setup like this
> >
> >         p.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
> >
> > and the client is implemented with the following decoders
> >
> >         e.getChannel().getPipeline().addLast("frameDecoder", new
> > DelimiterBasedFrameDecoder(65535, Delimiters.lineDelimiter()(0),
> > Delimiters.lineDelimiter()(1)))
> >         e.getChannel().getPipeline().addLast("encoder",      new
> > StringEncoder(CharsetUtil.UTF_8));
> >
> > I suppose the problem might be related to the "frameDecoder", which, to
> be
> > frank, I don't remember why I used it. So what would be the best setup
> for a
> > high-performance (10+K messages/second) client/server for this simple
> text
> > protocol ? I could use 0MQ for that, but Netty being pure Java, it's
> easier
> > to deploy.
> >
> > Thanks,
> >
> >  -- Sébastien
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > netty-users mailing list
> > netty-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/netty-users
> >
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20101103/c5756827/attachment-0001.html 


More information about the netty-users mailing list