10

Can someone brief about the difference between these looking-similar techniques?

  • Websocket
  • Server sent events (SSE)
  • HTTP2's Server Pushing

I knew all these 3 are "pushing" response from server instead of requesting by the client.

At the first look, it seems all are same.I need to get more clarity about the differences.

Sundararaj Govindasamy
  • 8,180
  • 5
  • 44
  • 77

1 Answers1

15

Websockets: asynchronous communication in both directions. So far doesn't work well with HTTP/2, but efforts are ongoing to make it so. (For example WISH and websockets2-over-http2.)

SSE: server can notify the browser of events. Uses normal HTTP and works well even with HTTP/2. It's possible to emulate asynchronous communication in both directions with SSE by issuing notifications from client to server via regular POST requests, in HTTP/2 these requests go in the same socket with everything else for the same origin and therefore the cost of establishing a new connection can be avoided. However, there may be processing costs on the server side for processing a POST request which are greater than using native websockets.

HTTP/2 Push: absolutely unrelated to the two above, it is a mechanism for a server to push assets to the browser in advance. Possible application: sending CSSs and Javascripts while the PHP engine is creating the HTML. In theory, HTTP/2 Push and SSE can be combined to make events available to the browser without the initial round-trip delay.

Community
  • 1
  • 1
dsign
  • 12,340
  • 6
  • 59
  • 82
  • This is a cool short version... but it hides pitfalls and inaccuracies in favor of providing a good overview, There's more information [here](http://stackoverflow.com/a/28197906/4025095), [here](http://stackoverflow.com/questions/5195452/websockets-vs-server-sent-events-eventsource) and [here](http://stackoverflow.com/questions/28582935/does-http-2-make-websockets-obsolete)... Also, Websockets works perfectly with HTTP/2 by falling back to HTTP/1.1 during the handshake. Past efforts to merge HTTP/2 with Websockets have been abandoned and though there might be new efforts, I don't know of any. – Myst Oct 20 '16 at 16:36
  • @Myst: See edits by Daniel Stenberg to my answer. WISH and websockets2-over-http2 are being discussed at the w3-wg mailing list. – dsign Oct 24 '16 at 11:22