I have a netty web socket server running to which various native javascript clients connect. Now what I want to do is to get requests for data from the clients and pass back data according to what each client requested. There is a class A that actually needs to send continuous data asynchronously(ie: not a simple request reply model)to the client according to the request.
The question is – at class A , I have all the data that I need to send but how to figure out which data has to be sent to which client(has to be according to the client requests) , ie: how do I map the client requests , data to be sent from class A and the channel over which the data needs to be sent from class A. (I store all the channels in a shared ChannelGroup).
You might want to try this.
Instance a DefaultChannelGroup:
DefaultChannelGroup myChannels = new DefaultChannelGroup("myChannels")When a web socket connect is established, add it to the channel group:
myChannels.add()Add the channel id and your request id to a hashmap
When you have data to write, I assume that you have the request id. Use it to look up your channel id in the hashmap
Then get the channel from the channel group:
myCahnnels.find(channelId)Lastly, write the data to the channel.
Hope this helps.