netty websocket + continuous PERIODIC data push

1.6k views Asked by At

What would be the best way to continuously push some data periodically(say every n seconds) from a websocket server in netty?

EDIT :

I came across this post : Best way to send continuous data in Java using Netty and according to the answer,while/sleep wouldnt be very scalable, how does one schedule a job on an Executor ?

1

There are 1 answers

0
Nicholas On BEST ANSWER
  1. WebSocket client connects to your Netty server, handshakes and establishes a websocket connection.
  2. The server registers the client's channel somewhere where it can be retrieved when there's data to send. (I use a ChannelGroup in a singleton)
  3. The scheduled job fires, gets some data from somewhere, then gets a reference to the client's channel and writes the data to it.
  4. The client channel's pipeline should have a few encoders in it that marshal the scheduled job supplied data into websocket frames.