10

I am developing a web app in which I want that when some changes in database occurs, server sends response to particular client(like push notification). And I want this notification to be sent client's browser. I don't want to use polling.

What can I do? I think it's possible using SSE, but I am not clear.
I want to know

  • Is it possible to send response to particular client without client's request(without polling).
  • How server will detect that particular client?

please help me.

peterh
  • 9,698
  • 15
  • 68
  • 87
Rikin Thakkar
  • 1,258
  • 3
  • 12
  • 27
  • As you've said, SSE seems to be the way to go. What, more precisely, is not clear on the HTML5 example you link to? Also consider this 2013 Sinatra example: http://html5hacks.com/blog/2013/04/21/push-notifications-to-the-browser-with-server-sent-events/ and current proposed W3C recommendation: http://www.w3.org/TR/eventsource/ – Ciro Santilli新疆棉花TRUMP BAN BAD Dec 10 '14 at 16:02
  • Possible duplicate of [Is there some way to PUSH data from web server to browser?](http://stackoverflow.com/questions/19995/is-there-some-way-to-push-data-from-web-server-to-browser) – Ciro Santilli新疆棉花TRUMP BAN BAD Jan 06 '16 at 18:26

1 Answers1

5

There is Web Notification. And there you can see the browsers that support it.

Gros Lalo
  • 998
  • 7
  • 18
  • hey u know what i want actualy..? I want that types of news updates like facebook gives at the top-right side of the page.. Any idea how to do this without using polling..? – Rikin Thakkar Sep 11 '12 at 11:26
  • Well if you have a webserver and you want the notifications to come through while the app/site is running in your browser then you can use WebSocket. WebSocket does not require polling. So, when there is data available or, a change that you want to communicate to the connected browsers you can then push them. Do you know about WebSockets? – Gros Lalo Sep 11 '12 at 11:33
  • yaaa.. i know websockets but i want to know which is best option in my case websockets or SSE..? – Rikin Thakkar Sep 11 '12 at 12:06
  • It is hard to tell as your case it quite limited. If it is only about receiving notifications then both are equally valid in my opinion. I do not know much about the server side implementation for SSE but for web-socket it is quite easy even if you are building things from scratch. Also, if your case evolves then you should consider constraints such as, SSE is uni-directional while with web-sockets it is bi-directional. So, it depends as you can see. – Gros Lalo Sep 11 '12 at 13:40
  • No worries. Somehow i feel i did not do much to help :) – Gros Lalo Sep 12 '12 at 08:47
  • Mmmm, isn't Web Notifications for showing a popup outside of the browser? Can you give a working example of server to browser data push? – Ciro Santilli新疆棉花TRUMP BAN BAD Dec 10 '14 at 15:40