What is the difference between Long-Polling, WebSockets, and Server-Sent Events?
Long-Polling, WebSockets, and Server-Sent Events are popular communication protocols between a client
like a web browser and a web server
sequence of events for regular HTTP request: 1. The client opens a connection and requests data from the server 2. The server calculates the response 3. The server sends the response back to the client on the opened request
WebSocket provides Full duplex communication channels over a single TCP connection
It provides a persistent connection between a client and a server
that both parties can use to start sending data at any time
The client establishes a WebSocket connection through a process known as the WebSocket handshake
If the process succeeds, then the server and client can exchange data in both directions at any time
The WebSocket protocol enables communication between a client and a server with lower overheads
facilitating real-time data transfer from and to the server
This is made possible by providing a standardized way for the server to send content to the browser
without being asked by the client
and allowing for messages to be passed back and forth while keeping the connection open * In this way, a two-way (bi-directional) ongoing conversation can take place between a client and a server