Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" means in WebSocket Protocol

I don't understand the meaning of "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" in RFC 6455. Why does the server need this magic string? And why does the WebSocket protocol need this mechanism?

like image 705
Hakju Oh Avatar asked Nov 19 '12 14:11

Hakju Oh


People also ask

What protocol does WebSocket use?

The WebSocket protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. By default the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over TLS [RFC2818].

How does a WebSocket protocol work?

WebSocket uses a unified TCP connection and needs one party to terminate the connection. Until it happens, the connection remains active. HTTP needs to build a distinct connection for separate requests. Once the request is completed, the connection breaks automatically.

What is Ping and Pong in WebSocket?

A ping or pong is just a regular frame, but it's a control frame. Pings have an opcode of 0x9 , and pongs have an opcode of 0xA . When you get a ping, send back a pong with the exact same Payload Data as the ping (for pings and pongs, the max payload length is 125).

What is WebSocket key?

The |Sec-WebSocket-Key| header field is used in the WebSocket opening handshake. It is sent from the client to the server to provide part of the information used by the server to prove that it received a valid WebSocket opening handshake.


2 Answers

The RFC explains it. It is a GUID, selected because it is "unlikely to be used by network endpoints that do not understand the WebSocket Protocol". See RFC 6455.

If you're interested in the specifics of the format for GUIDs like that, see RFC 4122.

like image 195
David Schwartz Avatar answered Oct 02 '22 17:10

David Schwartz


From the Quora answer:

There is no reason for choosing the magic string. The particular magic string GUID was chosen to add some level of integrity to the WebSockets protocol, because the string is globally unique.

The RFC (RFC 6455 - The WebSocket Protocol) only says:

...concatenate this with the Globally Unique Identifier (GUID, [RFC4122]) "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" in string form, which is unlikely to be used by network endpoints that do not understand the WebSocket Protocol.

Hope that answers your question.

like image 26
chaudharyp Avatar answered Oct 02 '22 16:10

chaudharyp