Protocol implementation, Netty socket server, J2ME client

Nicholas Clare nickclare at gmail.com
Fri Apr 10 08:40:44 EDT 2009


Hi,

 It doesn't seem like there's a simple example, although it is
mentioned in the ProtobufDecoder javadocs. I've written a very simple
example, which I've attached, but I not all that knowledgable of Netty
(well, not yet). So I hope my example can help, but maybe some more
experienced readers will be able to give some more advice.

>From what I can see, to use the LengthFieldBasedFrameDecoder, you have
to layer another decoder on top of it. The
LengthFieldBasedFrameDecoder just makes sure that the decoder you
write doesn't have to keep checking if enough data has arrived yet.
Also, because the LengthFieldBasedFrameDecoder ensures that you get
just enough data at once, your custom decoder can be based on
OneToOneDecoder.

I've put all the classes in one file to make it easier to send.

I hope this helps you along,
Nick

On Fri, Apr 10, 2009 at 1:22 PM, Karasko <karas at uralweb.ru> wrote:
>
> Thanks , Nicholas. I'll consider your ideas.
> Is there some example of LengthFieldBasedFrameDecoder using ? Didn't find it in DOCs.
>
>
> Hi
>
> A while ago I wrote server-side code to communicate with a J2ME
> client. Looking back now, the way I did it was wrong, so here's what
> I'd recommend for you: I'd use a simple binary protocol, that has a
> message length field. So a frame could be something like this:
>
> len (4 bytes) | message type (1 byte, or more, depending on what you
> need) | your content
>
> You can then use the LengthFieldBasedFrameDecoder class in Netty to do
> your decoding on the server side. On the client side, it shouldn't be
> too difficult to read in the length, and then read the rest of the
> message. You can also make this extensible by having the server or
> client ignore messages with a type it doesn't understand. So, for
> example, text messages could be message type 1, pngs message type 2,
> and so on.
>
> As for security, I'm sorry, I'm not too knowledgeable about that, so
> hopefully someone else can help you. I don't know what J2ME supports
> in that area, but it might be possible to do some basic encryption.
>
> I'm not really an expert, but I hope what I've suggested can maybe help you,
> Nick
>
> On Wed, Apr 8, 2009 at 2:09 PM, Karasko <karas at uralweb.ru> wrote:
>>
>> Hi, everyone.
>> I am writing a sokcet server, using Netty, which would be serve a requests from
>> J2ME devices (MIDP 2.0, CLDC). I am new person for networking, and concurrent programming,
>> so any advice or critics is accepted.
>>
>> Typical request is to retrieve some data from SQL server, based on text query.
>>
>> Response could be a text of various lenght, or sometimes binary data (i.e. PNG image).
>>
>> Can you advise some prototype of simple protocol for this, which i can
>> easily implement on client side J2ME device with standart packages:
>>
>> java.io.*;
>> javax.microedition.io;
>>
>> I need protocol to be
>> 1) extensible (adding new functionality doesn't require to rewrite code everywhere)
>> 2) compact (less traffic is better)
>> 3) secure (i don't know how to implement it yet, some advices will be nice)
>>
>>
>> I also want to know how to send an PNG image (or whatever binary data) over socket connection from server..
>> I think "new line" frame delimiter should be changed for smth else ?
>>
>> --
>> View this message in context: http://n2.nabble.com/Protocol-implementation%2C-Netty-socket-server%2C-J2ME-client-tp2604867p2604867.html
>> Sent from the Netty User Group mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> 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
>
>
>
> --
> View this message in context: http://n2.nabble.com/Protocol-implementation%2C-Netty-socket-server%2C-J2ME-client-tp2604867p2615713.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestServer.java
Type: application/octet-stream
Size: 2798 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20090410/6b9c0c83/attachment.obj 


More information about the netty-users mailing list