It is not repeated HTTP polling
After the upgrade, either endpoint can send messages without waiting for a new browser request.
Trace the HTTP upgrade, frame flow, heartbeat risk, close behavior, and reconnection decisions behind browser-to-IoT WebSocket links
WebSocket starts as an HTTP request, upgrades to a persistent message channel, and then moves small frames in both directions over one connection. Use this workbench to see what changes at each state and where browser IoT dashboards usually fail: idle paths, missed heartbeats, close handling, and reconnection.
Start with the scenario buttons, then step through the exchange. The scene, stage cards, frame fields, and diagnosis cards all update together.
After the upgrade, either endpoint can send messages without waiting for a new browser request.
JavaScript gets `open`, `message`, `error`, and `close` events. It does not expose raw protocol Ping/Pong controls.
Text and binary frames carry application data. Ping, pong, and close are control frames with stricter size and fragmentation rules.
NATs, proxies, mobile network changes, or server restarts can leave a connection looking idle until a heartbeat or write detects the problem.
Use Play or Step to move through the current scenario. Adjust payload size and heartbeat timing to see the frame overhead and connection health change.
The browser asks the server to switch this HTTP connection to WebSocket.
Single unfragmented message in this teaching model.
Application text payload.
Client-to-server browser frames are masked.
Payload length fits in the base field.
2 base + 4 masking-key bytes.
Header plus selected payload size.
The model keeps the learner-facing numbers simple, but the labels follow RFC 6455 and the browser WebSocket API.
0 CONNECTING, 1 OPEN, 2 CLOSING, and 3 CLOSED are the browser API states. They describe the JavaScript object, not every TCP/TLS detail.
0x1 carries UTF-8 text. 0x2 carries binary data. Continuation frames use 0x0 when a message is fragmented.
0x8 closes, 0x9 pings, and 0xA pongs. Control frames are short and must not be fragmented.
WebSocket is strong for browser dashboards and live control. Constrained devices often use MQTT, CoAP, or another IoT-specific protocol behind the gateway.
Run Clean upgrade and step to stage 2. Which response code confirms the switch from HTTP request/response to WebSocket frames?
Set frame direction to server -> client. What happens to the MASK field and why is it different from browser-to-server traffic?
Run Idle timeout, then lower the path idle timeout or raise the heartbeat interval. Which diagnosis card changes first?
Raise the reconnect attempt number. Why should a fleet add jitter and a maximum delay instead of reconnecting every device immediately?
The browser WebSocket constructor gives scripts a message-oriented API. Scripts send strings, Blobs, ArrayBuffers, or typed arrays and receive events. They do not build raw RFC frames directly. The browser implementation handles client masking, UTF-8 validation for text messages, fragmentation, TLS integration for `wss://`, and protocol-level responses such as Pong to an incoming Ping.
The WebSocket Protocol: HTTP/1.1 opening handshake, frame format, masking, opcodes, close behavior, and security considerations.
The browser-facing WebSocket API, ready states, events, and integration with the web platform.
Bootstrapping WebSockets with HTTP/2 using extended CONNECT and the `:protocol` pseudo-header.
Registered close codes, opcodes, extension names, and subprotocol names.