質問

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. 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.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top