1, Resume socket connection, start server
2, the client writes the data inside the HTML to establish the connection
<script type= "Text/javascript" >
var socket = new WebSocket ("Ws://127.0.0.1:8002/xxoo");
...
</script>
3, both sides build handshake
The server gets the data that the client sent over
Get the Sec-websocket-key from the head.
Take magic_string and Sec-websocket-key for HMAC1 encryption, and then Base64 encryption
Return the encrypted results to the client
4 If his encrypted results are returned to the client
If the same as the client, continue the connection,
If it is not the same, the client disconnects from the server
5, the client and the service side of the transfer of data, the need for packet-and-package process, the client's JavaScript has encapsulated package and package process,
But the socket server needs to be implemented manually.
6, the process of unpacking is divided into 3 steps: Ps:payload is an identity, telling the program to do it to me, followed by something else, like masking key
And the content of the data
1, if the length of payload is less than 125, the data behind
2, if payload length is equal to 126, then 16 bits is masking key, after masking key is the data
3, if payload length is equal to 127, then the 64 bits behind it is masking key, which is the data behind masking key.
7. Packets are also required when the server sends data to the client.
WebSocket--How it works