websocket protocol

# Websocket protocol

1. Ethereal

wireshark rules: tcp.port == 9000

2. The analytical results

Client requests:

GET /ws/test_2 HTTP/1.1
Host: localhost:9000
Connection: Upgrade
Upgrade: websocket
Origin: http://192.168***:9000
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: t55Td8j76+BHL9vRhPFXCQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

The server responded:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 4rAk+P4vM9mrrpKOiDCDSYQpXPA=

Interpretation:

  • Connection: Connection must be set to Upgrade, it indicates that the client wishes to connect to upgrade
  • Upgrade: Upgrade must be set to WebSocket, after obtaining the express server response, use HTTP to upgrade the HTTP protocol conversion (upgrade) for the WebSocket protocol.
  • Sec-WebSocket-key: a random string, is used to verify the protocol is not HTTP protocol WebSocket protocol
  • Sec-WebSocket-Version: indication of which version WebSocket.
  • Sec-WebSocket-Accept: calculated Sec-WebSocket-Accept and special string. Verify whether the agreement is WebSocket protocol.
  • Sec-WebSocket-Location: corresponding to the Host field, indicating a request address WebSocket protocol.
  • HTTP / 1.1 101 Switching Protocols: 101 status code indicates that the upgrade protocol, after returning a status code 101, HTTP protocol to complete the work, is converted to the WebSocket protocol. Then it can be a full-duplex two-way communication.

Guess you like

Origin www.cnblogs.com/wodeboke-y/p/11600881.html