I want to implement basic server push mechanism using websockets in netty ( not a chat application). Can anyone provide some pointers and example...
Asked
Active
Viewed 4,497 times
1 Answers
3
Take a look at the netty WebSocket Server xsource examples. They're quite good and self explanatory. Also, I have been putting together a test project to demonstrate Ajax push using netty. See the websocket package in netty-ajax-server.

Nicholas
- 15,916
- 4
- 42
- 66
-
Thanks for the quick reply.I went through the netty-ajax-server example.I was wondering if there would be some way to send data that is generated on the fly. For eg: I have a WebSocketServerHandler class There is another class C which generates data on the fly, how can I send data generated by C through the websocket ? – Rndm Jun 02 '12 at 10:50
-
1First off, you need the websocket client to connect to the server and wait for data. (i.e. you cannot initiate a websocket connection to a client unilaterally from the server.) Then, you need to keep a reference to the client's Channel somewhere where it can be referenced from the C class instance. The netty-ajax-server uses a ChannelGroup in a singleton. Then the C instance needs to get the Channel reference and write the dynamically generated data to the channel which will deliver it to the client. You also need to make sure you have the appropriate downstream handlers to encode the data. – Nicholas Jun 02 '12 at 17:04