Long‐Polling vs WebSocket vs Server‐Sent Events - rFronteddu/general_wiki GitHub Wiki
Long-Polling, WebSockets, and Server-Sent Events are popular communication protocols between a client like a web browser and a web server.
A standard HTTP web requests looks like:
- Client opens a connection and requests data from the server
- The server calculates the response
- The server sends the response back to the client on the opened request
Ajax Polling
Most AJAX applications have the client repeatedly poll a server for data. This creates extra overhead even if there is no data change.
HTTP Long-Polling
The server does not reply until it his ready. This technique is sometimes referred to as Hanging GET. These calls still have a timeout
WebSockets
They provide full duplex communication channels over a single TCP connection. They provide a persistent connection between a client and a server that both parties can use to start sending data at any time.
This connection has lower overheads, facilitating real-time data transfer from and to the server.
Server-Sent Events (SSEs)
Under SSEs, the client establishes a persistent and long-term connection with the server which uses this connection to send data to the client. If the client needs to send data it has to use a different technology.