Sundararaj Govindasamy
Sundararaj Govindasamy

Reputation: 8495

What is the difference between Websocket,Server Sent Events (SSE) and HTTP2's Server Pushing?

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

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.

Upvotes: 10

Views: 5050

Answers (1)

dsign
dsign

Reputation: 12700

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.

Upvotes: 14

Related Questions