Web sites migrate only to Socket.io 1.3.4

When I used Socket.io 0.9.16, I could configure the desired and only transport (websockets). No, I upgraded to version 1 (1.3.4) and cannot figure out how to limit the transport.

It looks like he starts a connection with the survey, and then updates to websockets if he wants to. I want it to start and always only work on websites.

+4
source share
1 answer

All WebSocket connections start with an HTTP request. This is how the specification works for webSocket. The client requests an update to the webSocket protocol in this first HTTP request, and if the server agrees, the socket is "updated" to the webSocket protocol.

If the server does not support webSocket and does not agree with the update, it socket.ioalso sends polling parameters with this first HTTP request, so if it does not switch to webSocket, it will immediately start with an http poll.

So, the short answer is that if you look at network tracing, you might think that it starts with an HTTP poll, but it's really just an HTTP request that initiates a connection to WebSocket. So it should be.

, WebSocket, .

webSocket:

GET /chat HTTP/1.1
Host: example.com:8000
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13

, webSocket:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

, webSocket , HTTP-, - , , webSocket.

"" webSocket.

+5

All Articles