Game Development Reference
In-Depth Information
Listing 10-6. The Connection is Upgraded to WebSocket
SpecifcationGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
FullWebSocketKey = concatenate(Sec-WebSocket-Key, SpecifcationGUID);
-> dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11
KeyHash = SHA-1(FullWebSocketKey);
-> 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4
0xea
Sec-Websocket-Accept = base64(KeyHash)
-> s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
After the client has successfully completed the challenge, the connection is upgraded from HTTP to WebSocket
and all communication must be performed through WebSocket.
Unlike TCP, WebSocket is a message-based protocol. No end of a WebSocket connection can receive a half-
transmitted message. At the protocol level, each message begins with a header defining the length of the message, the
type (text, binary, or control), and other metadata. The message payload immediately follows the message header. All
incoming messages will include a 32-bit mask, which must be applied to the entire payload with an XOR operation.
Each message will have a different mask.
The header begins with a 16-bit mask (light background) and up to 12 bytes of optional header (dark
background) shown in Figure 10-5 .
FINAL-FRAGMENT
RSV1
RSV2
RSV3
OPCODE
(4-bits)
MASK-PRESENT
PAYLOAD LENGTH
(7-bits)
EXTENDED PAYLOAD
LENGTH
(16 or 64-bits)
MASK
(32-bits)
Figure 10-5. WebSocket packet data layout
 
Search WWH ::




Custom Search