Skip to content
EduVerse

WebSockets

Explained

Protocol / format

Also known as: WS

Protocol for real-time, two-way communication between client and server over one persistent connection.

WebSockets, explained

Written by EduVerse

What it is

WebSockets is a protocol for a long-lived, two-way connection between a browser and a server. It starts as an ordinary HTTP request that asks to upgrade the connection, and from then on both sides can send messages at any moment. Addresses start with ws://, or wss:// for the encrypted version.

Why teams use it

With plain HTTP the client always has to ask first, so live updates mean polling the server every few seconds, which is wasteful and slow. Over a WebSocket the server pushes new data the moment it exists. The trade-off is that open connections cost server resources, and spreading them over several servers takes extra work.

An example from work

You build a chat feature and open DevTools. In the Network tab, filtered on WS, you find one request with status 101 Switching Protocols, and its Messages tab lists every message sent and received as it happens. After a deploy the connection drops, so your client code needs to reconnect on its own.

Our own explanation, not a quote from the book.

Where it fits

Chat, live feeds, multiplayer games, real-time dashboards

Coverage in the book

Explained

Explained and compared with alternatives, so you know where and why it’s used.

Appears in