2

I have a web server which I want to send data to the client when the server detects a change in the data base. I want the client to receive the data without polling.

What is the best way to achieve this?

(I read a bit about SSE - server sent events, but not sure this is the way to go)

Thanks

Licson
  • 2,231
  • 18
  • 26
omer bach
  • 2,345
  • 5
  • 30
  • 46

3 Answers3

1

Yes, Server-Sent Events is appropriate technology for listening to changes on the server.

If you're only listening, then SSE is better (faster, lightweight, HTTP-compatible) than a 2-way WebSocket.

Kornel
  • 97,764
  • 37
  • 219
  • 309
0

If polling is not an option, you can think about the better technique, WebSockets, if your server supports it (and your target browser!). One way or another, you need a connection opened by the client to the server, though.

Greg
  • 3,370
  • 3
  • 18
  • 20
  • Why is WebSockets better than SSE ? – omer bach Feb 28 '13 at 06:28
  • I said it's better than traditional polling techniques (IMHO), not than SSE. Both WS and SSE are good at what they do, read more there: http://stackoverflow.com/questions/5195452/websockets-vs-server-sent-events-eventsource – Greg Feb 28 '13 at 06:56
0

The answer would vary depending on the freedom you have with client-side Javascript.

If your app gives you complete freedom, you could even set up your client to be a JMS listener and communicate JMS messages from client to server. For ex, you can use Apache Ajax.

Another option is to set up your web client to be redis client using, for ex, Webdis

As you have mentioned, Server-sent-events is an option too, so is WebSockets. You need to choose based on your constraints.

2020
  • 2,821
  • 2
  • 23
  • 40