WebSockets create two-way, low-latency communication channels between browser and server, perfect for scenarios requiring two-way communication with minimal latency, i.e. multiplayer games.
This is in contrast to the traditional HTTP request-response model, where the browser initiates the communication, with significant overhead due to establishing TCP connections and HTTP headers.
Server sends majority of messages in real-time apps; client mostly listens & sends occasional updates. E.g. in chat app, user may connect to many rooms with many participants, so messages received far exceeds sent.
How it builds the connects
They use HTTP to establish the connection, then upgrade it to TCP connection on top of which the WebSocket protocol can be used, so WebSockets cannot benefit from any HTTP feature.
websocketsUpdated May 24, 2024

Server-Sent Events