HTTP Servers are non-persistent i.e. after the client requests data and the server sends back the response, the connection closes (3-way handshake ends). If client requests data again, a new connection is established. Hence, the connection is not continuous and non-persistent.

To resolve this, we have WS servers which provide persistent connection between client and server i.e. WebSockets provide a way to establish a persistent, full-duplex communication channel over a single TCP connection between the client (typically a web browser) and the server. Client can send multiple requests and server can send multiple responses without any interruption since connection is persistent. This is highly beneficial in specific use-cases like chat apps, live score updates where real-time communication happens.

Beneficial for large amounts of data sent in almost continuous intervals

Real-World problem : Valorant high ping teleportation

WS Servers

image.png

HTTP Servers

image.png

In chat apps, we can use polling/long-polling if we are restricted to HTTP servers i.e. keep sending requests to backend in intervals to see if it responds with new data…this process is not a good practice hence we use WebSocket servers which create persistent, real-time connections with the clients that means server can send updates to client whenever there is new data without need of client sending multiple request(s).

If there’s a server side event (updates in server data), server will want to push that data to client but if there’s no connection in the first place (because it ended after initial response/HTTP server), the only way to get that data is polling…whereas in WebSocket servers connection is persistent so it can send data automatically without any polling needs as connection exists.