WebSockets & Server-Sent Events
Read this concept as one more decision made about a packet in flight. The widget below lets you change the inputs and watch the consequence instead of memorising the rule.
Why it matters
Long-lived browser communication still starts as an ordinary request, then changes how bytes flow afterward. The upgrade and the streaming format determine which side may send and how failures surface.
On the wire
A WebSocket client sends an HTTP Upgrade request with Sec-WebSocket-Key and version, the server answers 101 Switching Protocols, and the connection then carries masked client frames and unmasked server frames. Server-Sent Events instead keep the original response open and deliver text events separated by blank lines.
When it breaks
A proxy that does not understand Upgrade drops the connection after the handshake, leaving the application retrying forever. An idle timeout on an intermediary silently closes a long-lived stream, and SSE without a Last-Event-ID loses events during reconnect.
WebSocket lifecycle
Send protocol events one at a time; only events valid in the current state are offered.
Available events in CLOSED
Choose an event to drive the connection forward.