How to reliable and efficiently implement a string protocol

Christian Migowski chrismfwrd at gmail.com
Tue Nov 2 11:15:52 EDT 2010


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
>



More information about the netty-users mailing list