简体   繁体   中英

Connection based UDP protocol in Netty

I need to make a client for an existing protocol. I believe Netty would make that relatively straightforward, but could do with a bit of getting started help.

The protocol uses a connection based approach, but layered on top of UDP, with the actual messages inside a transport envelope, with out-of-order / slow / missing packets, session numbering, and the like all the job of the client.

What would be the best way to create the pipelines & frame decoders etc in netty to achieve this. I've only used netty in a very basic way before - so any advice would be very welcome.

Thanks!

James

It sounds pretty painful. I'm a regular netty user, but I would not implement a protocol like this in Netty (not a ding against netty, but it's implemented elsewhere), at least, the way you have described it. Before you go down this road, I would take a look at JGroups which has implemented a "reliable UDP" stack which features all the transport functionality you outlined.

My first stab at this (if I was on a desert island) would be something like:

Downstream

sendMessage
  --> MessageSplitHandler
    --> MessageFragmentBufferHandler
RetransmitRequester -->

where:

  • MessageSplitHandler breaks up the sent message into UDP friendly sized MessageFragments (datagrams) (of which there might be one if the origial message is small enough). For each MessageFragment created from the parent message, assigns each:
    • the unique id of the parent message.
    • a sequence number
    • the total number of fragments created from the original
  • MessageFragmentBufferHandler stores each MessageFragment until the remote end has confirmed the message has been received (or you elect to timeout the message re-assembly and ditch unconfirmed messages). Otherwise, keep them around in case the remote requests MessageFragment re-transmitts (probably by parent-message-id and fragment sequence.

Upstream

This will be more or less the reverse the downstream.

   MessageFragmentDecoder <--
  MessageFragmentBuffer <--
 MessageReAssember <--
onMessage
  • MessageFragmentDecoder: decodes the datagram into a MessageFragment.
  • MessageFragmentBuffer: stores arrays of MessageFragments until all sequences have been received. If a message is received out of sequence, assume the intermediate was lost and ask the sender to send it again (by unique-id/sequence)
  • MessageReAssember: When all MessageFragments have been received, this guy re-assembles the original message and passes it to the message receiver.

I think that would be the general idea, but there's probably 200-300 corner cases in there....

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