Aller au contenu
uencoder

WebSocket Protocol Référence

Référence pour WebSocket (RFC 6455): framing, handshake, subprotocols, et extensions.

Connection Lifecycle

WebSocket connections start with an HTTP Upgrade handshake carrying the Sec-WebSocket-Key header. The server responds with 101 Switching Protocols and a derived accept key. After the handshake, the connection upgrades to the WebSocket protocol with binary framing. The connection remains open until either side sends a Close frame or the TCP connection drops. Ping/Pong frames implement keepalive and latency measurement.

handshake
HTTP Upgrade
101 Switching Protocols
framing
Binary frames after upgrade
opcode + payload
ping/pong
Keepalive mechanism
measure latency

Framing and Extensions

WebSocket frames have opcodes: text (0x1), binary (0x2), close (0x8), ping (0x9), pong (0xA). Payloads can be fragmented across continuation frames. The masking bit requires client-to-server frames to be XOR-masked with a 4-byte key. Extensions like permessage-deflate compress message payloads. Subprotocols negotiated in the handshake (e.g., STOMP, WAMP) define application-level semantics. Maximum frame size is implementation-dependent.

opcodes
Text, binary, control
0x1-0xA
masking
Client frames masked
XOR with 4-byte key
deflate
permessage-deflate
compression extension

Outils associés

参考链接