How to send nessage to a client in netty

2019-08-09 04:08发布

问题:

I am a Netty beginner and struggling to manage client list. I save device ID and divice name when a client connects and when a different client wants to send a message to the client by device ID, how can I handle this? I have seen the examples how to use ChannelGroup to save the connected clients. But it is only for channel and it has attributeKey but it is for different purpose. Do I just map or list instead of ChannelGroup? Is there any good idea? Your answer would be appreciated.

回答1:

You could just implement your own ChannelGroup that stores the clients differently and lets you find a client by ID. But since you only want to relay a message to ONE connected client I don't see much sense in using a group. As far as I understand ChannelGroups are supposed to make broadcast messages easier. I think a simple HashMap with the ID as key would be enough.



标签: netty