WebSocket Extensions & Sub-Protocols
WebSocket extensions (negotiated via Sec-WebSocket-Extensions) modify the framing or encoding of messages. Sub-protocols (negotiated via Sec-WebSocket-Protocol) define the application-level message structure.
Extensions
Modify frame encoding. Negotiated via Sec-WebSocket-Extensions.
Sub-protocols
Application-level message format. Negotiated via Sec-WebSocket-Protocol.
MQTT over WebSocket uses the WebSocket subprotocol identifier mqtt to tunnel MQTT binary frames inside WebSocket frames. Negotiated via Sec-WebSocket-Protocol: mqtt in the handshake. Required when MQTT clients (IoT devices, browsers) run in environments that only support WebSocket connections (port 80/443). AWS IoT Core, HiveMQ, and Mosquitto all support MQTT over WebSocket on port 443.
graphql-transport-ws is the modern WebSocket subprotocol for GraphQL subscriptions, maintained by The Guild. It replaces the older subscriptions-transport-ws. Uses the subprotocol identifier graphql-transport-ws. Messages are JSON objects with a type field (connection_init, subscribe, next, error, complete). Resolves several protocol problems in the legacy protocol: server-initiated keep-alives, proper error propagation, and clean stream termination.
STOMP (Simple Text Oriented Messaging Protocol) over WebSocket uses the subprotocol identifiers v10.stomp, v11.stomp, or v12.stomp. STOMP is a text-based messaging protocol similar to HTTP frames. WebSocket + STOMP is the standard integration for Spring WebSocket (Spring Boot) and popular with Java enterprise applications. SockJS is a fallback library that emulates WebSocket with long-polling when WebSocket is unavailable.