alessandro ferrucci
alessandro ferrucci

Reputation: 1291

Netty server for many long-lived TCP connections

I'm porting some TCP server/client code to Netty.

One question, the server will handle long-lived connections from many clients. I don't currently need and most likely won't need to do things like broadcast to all clients in a batch operations etc... but I just need a storage place for these channels and a mechanism that allows me to selectively send notifications down to the clients given some client ID.

My question is is a ChannelGroup an acceptable mechanism to hold these channels? When I first get a connection I will store the channel's ID with the client ID in a lookup map so that whenever I need to notify a particular client I will look up the channel ID I need to write to and then grap that Channel from the ChannelGroup and only send a message to that channel.

Anything wrong with that approach?

Thank you!

Upvotes: 0

Views: 1616

Answers (1)

forty-two
forty-two

Reputation: 12817

No, that seems reasonable, although I would just store the Channel with the client id, and possibly attach a listener to Channel#getCloseFuture() in order to maintain my mappings. However, a ChannelGroup is still useful, especially for closing "associated" channels as a unit.

Upvotes: 0

Related Questions