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.