Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need web-sockets?

Tags:

This is more of a n00b question, but I've never really known the answer.

so why do we need the websockets protocol?

and, what are the advantages over comet-style/long poll/hanging GET-style use of HTTP?

like image 479
phoenix24 Avatar asked Sep 01 '10 11:09

phoenix24


People also ask

Is WebSocket better than HTTP?

Unlike HTTP, where you have to constantly request updates, with websockets, updates are sent immediately when they are available. WebSockets keeps a single, persistent connection open while eliminating latency problems that arise with HTTP request/response-based methods.

What are WebSockets and how do they work?

WebSocket is an upgraded, quick, and seamless protocol to use when one needs to establish constant client-server communication. Even if the data is continuously transmitted, WebSocket ensure the connection is intact and data is highly secured in the process.

Are WebSockets still used?

Websockets are largely obsolete because nowadays, if you create a HTTP/2 fetch request, any existing keepalive connection to that server is used, so the overhead that pre-HTTP/2 XHR connections needed is lost and with it the advantage of Websockets.


1 Answers

Comet and Ajax can both deliver end-user experiences that provide desktop-like functionality and low user-perceived latency, only Web Sockets lives up to the promise of providing a native means to accurately and efficiently stream events to and from the browser with negligible latency.

With polling it makes unnecessary requests and, as a result, many connections are opened and closed needlessly in low-message-rate situations.(as with polling it sends HTTP requests at regular intervals and immediately receives a response.)

Web Sockets remove the overhead and dramatically reduce complexity.

like image 131
Spooks Avatar answered Oct 14 '22 08:10

Spooks