This episode dissects the WebSocket protocol conceptually: the RFC 6455 standard, full-duplex communication over a single TCP connection, the ws and wss schemes, and a comparison with polling, SSE, and HTTP/2 Server Push to decide when to use WebSocket.

After seeing the evolution of the real-time web in episode 1, it is time to dissect the WebSocket protocol itself. In this episode you will understand the standard that underpins every implementation: RFC 6455.
WebSocket is a communication protocol that provides full-duplex — both sides can send data simultaneously over a single persistent TCP connection. Unlike HTTP, where every message carries full headers, WebSocket sends data directly after the handshake with very minimal overhead.
RFC 6455 was ratified in 2011 and defines the WebSocket protocol completely: handshake, framing, masking, control frames, and closing procedures. Because it is a standard, all implementations — ws in Node.js, gorilla/websocket in Go, websockets in Python — can interoperate.
The most prominent characteristics of this protocol:
npx wscat -c ws://echo.websocket.eventsThe command npx wscat -c ws://echo.websocket.events connects you to a public echo server. Type anything and the server will mirror the same message back — the fastest way to feel full-duplex without writing code.
Just as HTTP has http:// and https://, WebSocket has two schemes:
ws://host:port/path
wss://host:port/pathThe ws://host:port/path format above shows that the port and path are optional — just like HTTP URLs, including the query string for carrying parameters.
Polling (episode 1) keeps doing repeated request-response with full headers every time. WebSocket sends a handshake once, then talks directly with lightweight frames. For frequent updates, WebSocket wins hands down; for rare, one-shot requests, HTTP polling is actually simpler.
SSE is a one-way long-lived HTTP connection with automatic reconnection. WebSocket is two-way and supports binary. The choice is simple:
HTTP/2 Server Push lets the server send resources before they are requested, but it is designed for asset caching, not for ongoing two-way communication. WebSocket remains the primary choice for interactive real-time messaging.
HTTP/3 is built on QUIC, which is faster than TCP for multiplexing. However, HTTP/3 is still request-response; for pure bidirectional streams, a future technology called WebTransport is more relevant — we will discuss it in a later episode.
WebSocket excels in scenarios demanding continuous data exchange:
WebSocket is not the answer to everything. Avoid it when:
Warning
WebSocket has no caching, versioning, or semantics like HTTP methods. Do not try to "imitate" REST over WebSocket without a clear reason — use the right protocol for the right job.
Every WebSocket connection goes through two major phases:
We will dissect the handshake phase in detail in the next episode. For now, the key thing to understand: this phase happens only once, and after it the connection "transforms" from HTTP into WebSocket.
An established connection can be used in several patterns:
These patterns are the foundation of applications like chat. We will practice implementing them from episode 5 onward and in depth in a later episode.
Episode 2 gives you a conceptual map of the WebSocket protocol: the RFC 6455 standard, the ws and wss schemes, and a comparison with polling, SSE, and HTTP/2 Server Push. You also now know when to use WebSocket and when not to.
Key takeaways:
wss:// is mandatory for production because it uses TLS.In the next episode we will dissect the handshake and connection lifecycle — the Upgrade and Sec-WebSocket-Key headers, the Sec-WebSocket-Accept calculation, the four connection states, the frame structure, and the heartbeat ping and pong mechanism. This is the technical core that makes the protocol work.