HTML and CSS Reference
In-Depth Information
Listing 11-1.
A Sample Client Connection Request
GET /chat HTTP/1.1
Host: server.
example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Version: 12
Origin:
http://example.com
The server takes the
Sec-WebSocket-Key
and appends the WebSocket “magic string” (
258EAFA5-E914-47DA-
95CA-C5AB0DC85B11
, per the Request for Comments [RFC]), and then SHA-1 and Base64 encode the output. The result
is returned in the server response as the
Sec-WebSocket-Accept
value. This response also marks the last time data will
traverse HTTP, as shown in the sample response in Listing 11-2.
Listing 11-2.
A Sample Response
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat
Sending and Receiving Data
Figure
11-1
illustrates the WebSocket handshake.
Figure 11-1.
WebSocket handshake