我正在尝试设置socket.io
连接,但连接会以transport error
消息结束。客户端和服务器都运行socket.io v2.0.3。
客户端
var _socket = io({
transports: ['websocket'],
query: {
token: userToken,
roomName: getRoomName(),
},
});
消息:
socket.io-client:manager attempting reconnect +5s
socket.io.min.js:1 socket.io-client:manager readyState closed +0ms
socket.io.min.js:1 socket.io-client:manager opening https://video.twoseven.xyz +1ms
socket.io.min.js:1 engine.io-client:socket creating transport "websocket" +1ms
socket.io.min.js:1 engine.io-client:socket setting transport websocket +1ms
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +2ms
socket.io.min.js:2 WebSocket connection to 'wss://video.twoseven.xyz/socket.io/?token=abcd&roomName=us&EIO=3&transport=websocket' failed: Invalid frame header
r.doOpen @ socket.io.min.js:2
r.open @ socket.io.min.js:2
r.open @ socket.io.min.js:1
r @ socket.io.min.js:1
r @ socket.io.min.js:1
r.open.r.connect @ socket.io.min.js:1
(anonymous) @ socket.io.min.js:1
socket.io.min.js:1 engine.io-client:socket socket error {"type":"TransportError","description":{"isTrusted":true}} +733ms
socket.io.min.js:1 socket.io-client:manager connect_error +1ms
socket.io.min.js:1 socket.io-client:manager cleanup +0ms
socket.io.min.js:1 socket.io-client:manager reconnect attempt error +1ms
socket.io.min.js:1 socket.io-client:manager will wait 4769ms before reconnect attempt +1ms
socket.io.min.js:1 engine.io-client:socket socket close with reason: "transport error" +0ms
Chrome开发者控制台从网络标签中报告以下内容:
General
Request URL:wss://video.twoseven.xyz/socket.io/?token=abcd&roomName=us&EIO=3&transport=websocket
Request Method:GET
Status Code:101 Switching Protocols
Response Headers
Connection:upgrade
Date:Thu, 19 Oct 2017 22:36:52 GMT
Sec-WebSocket-Accept:YJ3aZ2L+X+ANa1bJK3ECO/s7XVE=
Sec-WebSocket-Extensions:permessage-deflate
Server:nginx/1.11.8
Upgrade:websocket
服务器
const io = new socketio(server, {pingInterval: 3000, pingTimeout: 10000});
io.set('transports', ['websocket']);
消息:
engine handshaking client "yrFJADAHt-QQZsX6AAAA" +0ms
engine:socket sending packet "open" ({"sid":"yrFJADAHt-QQZsX6AAAA","upgrades":[],"pingInterval":3000,"pingTimeout":10000}) +3ms
engine:socket flushing buffer to transport +1ms
engine:ws writing "0{"sid":"yrFJADAHt-QQZsX6AAAA","upgrades":[],"pingInterval":3000,"pingTimeout":10000}" +1ms
engine:transport setting request +1ms
engine:socket sending packet "message" (0) +9ms
engine:socket flushing buffer to transport +19ms
engine:ws writing "40" +1ms
engine:socket sending packet "message" (2["authenticated"]) +91ms
engine:socket flushing buffer to transport +0ms
engine:ws writing "42["authenticated"]" +1ms
engine:socket transport error +136ms
engine:ws closing +2ms
从服务器日志中,我看到connection
事件已被触发并且执行正常,但最后一行显示为socket.emit('authenticated');
。此时运输似乎失败了