Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

First, the relationship between WebSocket and HTTP happen only at the very beginning of the protocol. To open a WebSocket, a client must first establish a HTTP Connection to the remote server in order to perform the WebSocket opening handshake. Once it done, the client send a request to upgrade the actual connection to WebSocket. The HTTP request include Connection, Upgrade and some new HTTP Header that has been standardized for the purpose of the WebSocket opening Handshake. Then, if the server accept the Upgrade request, the server will send back a response with the 101 Switching Protocols status code. Otherwise, it will response an error code.


Panel
titleFigure - Websocket Upgrade Example

Image Added


Message exchanges
Once the handshake is performed and successful, the connection has upgraded to the WebSocket Protocol and the relationship with the HTTP protocol end. At this point, both Client and Server have agreed to switch the protocol of this connection to WebSocket and cannot switch back to HTTP. 

Message exchanges

In the WebSocket Protocol, data are exchanged using sequences of frame to form WebSocket Messages. A message can transport either protocol-level signaling (Control Messages) or information (Data Messages). It can be summarized by its Type, Payload Length and Contents. WebSocket Messages can have 5 differents Types.   

Control MessageData Message
CloseText
PingBinary
Pong 

Control messages payload length cannot exceed 125 bytes and they cannot be fragmented (only one frame per message). Data message length can vary from 0 to 2^64 bytes and can be fragmented. A WebSocket message can always be sent into a single frame, but can be fragmented into multiple frames if it's a Data message.  

...