LightAtom

What Is a WebSocket?

A WebSocket is a connection that stays open, so the server and browser can send each other messages at any moment. It powers chat, live dashboards and multiplayer games.

A WebSocket is a persistent, full-duplex connection between a client and a server over a single TCP connection. It starts as an HTTP request that asks to “upgrade”, then both sides can send messages whenever they like, without new requests. URLs use ws:// or, encrypted, wss://.

How it works

The browser sends GET /chat with Upgrade: websocket, the server answers 101 Switching Protocols, and messages then flow both ways.

The upgrade

GET /chat HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

The server replies 101 Switching Protocols, and the same connection then carries WebSocket frames: text, binary, ping/pong keep-alives and close.

Why use it

HTTP is request-response: the server can't speak until asked. Before WebSockets, live pages polled every few seconds, wasting requests and adding delay. A WebSocket lets the server push the moment something happens, with tiny per-message overhead.

Alternatives

  • Server-Sent Events (SSE): a simple one-way stream from server to browser over plain HTTP; great for notifications and progress.
  • Long polling: a fallback where requests hang until there's news.
  • WebTransport: a newer QUIC-based option.

Practicalities

Proxies and load balancers must support upgrades and long-lived connections; idle connections need pings to survive NAT and proxy timeouts.

Examples

  • Slack, Discord and most web chat apps.
  • Live sports scores, stock tickers, collaborative editors.
  • Browser-based latency tests, which time messages bouncing off a server.

On a Mac

In Safari or Chrome developer tools › Network, filter by WS to see WebSocket connections and their individual messages. lsof -i -n -P | grep ESTABLISHED shows the long-lived TCP connections behind them.

See it in the app

LightAtom's connections view shows WebSocket connections as long-lived connections, typically on port 443, that stay open while apps like Slack are running.

Frequently asked questions

What is a WebSocket used for?

Real-time features: chat, notifications, live data, collaborative editing and multiplayer games.

Is WebSocket TCP or UDP?

TCP. It runs over the same connection as the HTTP request that started it, usually on port 80 or 443.

What is the difference between WebSocket and HTTP?

HTTP is request-response. A WebSocket stays open after the initial HTTP upgrade and lets both sides send messages at any time.

What is wss://?

A WebSocket over TLS, the encrypted equivalent of https://. Use it in production.

LightAtom team

The people who build LightAtom, a network monitor for macOS.