简体   繁体   中英

Sending and receiving different type of packets using Netty

I want to implement sending and receiving packets (I use this in OIO)

Step 1: Server -> Client, Packet A
Step 2: Client -> Server, Packet B
Step 3: Server -> Client, Packet C

When server send Packet A to client, Client should send boolean to server. Then if it's true server should send PACKET B to client. I don't know how to implement this with Netty. Please help me.

Note that the methods channelRead of the ChannelInboundHandler and the write and writeAndFlush methods of the ChannelHandlerContext takes objects as parameters.

You need to implement your own client and server along with encoders and decoders that receives and sends data based on the packet specifications you have. That is you need to encode Packet A, Packet B and Packet C and send to the client. Client should decode the packets and respond with a boolean which needs to be encoded and sent to the server. Server should then decode and process the boolean.

The above is a lot complicated. You can easily do this by sending JSON or any other form of data over the HTTP protocol because decoders and encoders for this protocol is already supported by netty. All you have to do then is to process the JSON data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM