4

i would like to know how the update messages in this stack overflow site have been implemented.

To be more precise, for example while i am trying to reply for question and i am in the middle of typing my response, i will see a message on top of the page saying a new answer has been added. How is this feature has been implemented.

AFAIK, the possible way can be HTML5 websocket or serversocket technology. is there any other way to achieve this kind of push notification system especially using java, spring and jquery environment?

Not sure how to tag this question. correct the tags if i am wrong.

keyser
  • 18,829
  • 16
  • 59
  • 101
Rohini Kumar
  • 249
  • 1
  • 5
  • 15
  • I'd mention [socket.io](http://socket.io/) which is an outstanding solution for such things, but doesn't fit your server-side backend. – Kos Oct 09 '12 at 14:32

3 Answers3

6

SO uses reverse ajax/comet technology to show those messages. I remember reading some discussion on meta about this feature, couldn't exactly find out the link for it at this moment. Will update as soon as I find.

Based on programming language framework name may change (websockets (or) socket.io etc.,), but at the end they all are from comet framework.

Update:

Here is SO meta discussion on this topic.

Community
  • 1
  • 1
kosa
  • 65,990
  • 13
  • 130
  • 167
2

I have used the Direct Web Remoting framework with success. (DWR).

Werner Kvalem Vesterås
  • 10,226
  • 5
  • 43
  • 50
  • DWR. another new thing. nice to know about it. seems very interesting and fitting in my environment (java, spring, jquery). Definitely give it a try – Rohini Kumar Oct 09 '12 at 14:43
2

There are several ways to achieve that:

  • Polling: using JQuery you issue a request regularly (every 5sec for examples) which retrieves the updates from the server.
  • Streaming: you issue a request, the server does not set a Content-Length to the response and "never" close the socket. This way you can send data from server to client whenever you want. But it means that for every client a connection is hold by your server.
  • Long polling: mix between the two previous ways. The connection is hold by the server but with a timeout. If no new data is available, the server closes the connection and the client reopen a new one after a moment.

Thoses are Push technologies: http://en.wikipedia.org/wiki/Push_technology

Of course there are over ways to achieve that.

mkhelif
  • 1,551
  • 10
  • 18