WebSocket subprotocols
A raw WebSocket connection just moves opaque frames; a subprotocol defines the
application-level message format running over it — MQTT, STOMP, WAMP, GraphQL
subscriptions and more. The client and server agree on one during the handshake
using the Sec-WebSocket-Protocol header. This reference lists common
IANA-registered subprotocol identifiers with their purpose.
How it works
The client lists the subprotocols it supports, most-preferred first; the server selects exactly one and echoes it back:
GET /chat HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Protocol: graphql-transport-ws, graphql-ws
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Protocol: graphql-transport-ws
The chosen token must be one the client offered, compared with exact casing. If
the server returns no Sec-WebSocket-Protocol header, the connection runs with
no application subprotocol. Names are coordinated in the IANA registry so
independent implementations interoperate.
Tips and notes
- List subprotocols in preference order; the server picks the first it supports.
- Tokens are case-sensitive and opaque — use the exact registered string.
- A server must never select a subprotocol the client did not offer.
- For public protocols, register the name with IANA to avoid collisions.