描述的不同之處我試圖更多地瞭解websockets協議。根據RFC 6455,該協議的步驟是握手,它與HTTP的升級請求開始:SocketIO websocket握手與RFC 6455
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
到該服務器與HTTP交換協議消息進行響應:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: chat
我試圖使用一個基於socketIO(nodeJS websockets庫)的簡單程序來觀察這個問題,我注意到客戶端發送服務器的第一條消息是:
GET /socket.io/?EIO=3&transport=polling&t=1443149751115-0 HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Origin: null
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Length: 101
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: null
Set-Cookie: io=3Z_TCqv9LKKXcWCjAAAD
Date: Fri, 25 Sep 2015 02:55:51 GMT
Connection: keep-alive
....0{"sid":"3Z_TCqv9LKKXcWCjAAAD","upgrades": ["websocket"],"pingInterval":25000,"pingTimeout":60000}
是SocketIO不遵循的WebSockets的RFC還是我失去了一些東西:到服務器響應?
這些差異是否記錄在任何地方? – SivaDotRender
@SivaDotRender - 它被記錄下來,除了原始實現者自己寫的以外,其他語言中還有很多socket.io實現。我不確定最好的文檔在哪裏,但有一些[這裏](https://github.com/socketio/engine.io-protocol)和[這裏](https://github.com/socketio/) socket.io的協議)。 – jfriend00