Reputation: 41
Although I spend a couple of hours going through tutorials, I have a hard time understanding Netty. I want to send a couple of different objects between client and server, but I don't know how to do it properly. It seems possible to just serialize an object and to send it like that and on the recieving end it is put together into an object of that class. However, I have read that there could be limitations concerning the size of that object. Also, I don't understand how to handle the channelRead-functions of the handlers, as they are also called when the object is not received in full length. Can I just wait until channelReadComplete is called and put the object back together then?
Since I want a couple of different object with variable length, I also wonder if it is advisable and possible to use ByteBuf instead and somehow read out the first byte that holds the information about the object-type and somehow casts the remaining received bytes in the correct type of object.
I would really appreciate some help on this.
TeaDrinkerJoe
Upvotes: 1
Views: 805
Reputation: 7983
You can use a netty Encoder
to encode or serialize your objects to bytes and write a Decoder
to decode or deserialize the received bytes. You can have your own serialization and deserialization implementations, but make sure that you can differentiate the objects in a continuous byte stream.
Upvotes: 0