WebSocket 相關 Protocol
Last updated
Was this helpful?
Last updated
Was this helpful?
WebSockets 不受 CORS 限制
不一定要在 Browser 使用
browser client 的 onmessage 事件只有在收到完整資料後才會觸發
WebSocker 架構在 HTTP 之上
會發出 HTTP GET request,然後才升級為 WebSocket
產生 client request
產生 server response
有關 Sec-Websocket-Key,在 client是隨意產生的 base64 字串
將 client 的 Sec-WebSocket-Key 與 magic string: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" 串接,, 然後再做 SHA-1 hash 之後再進行 base64 encoding
Server 最後要兩個 \r\n 來表示 Header 結束
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 of0xA
. 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). You might also get a pong without ever sending a ping; ignore this if it happens.