我正在使用带有socket.io的nodejs并表达框架工作。以下是我运行命令时获得的日志输出
DEBUG=* /bin/www
以下是日志输出。
engine intercepting request for path "/socket.io/" +2m
engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=1414498393419-0" +0ms
engine handshaking client "WECN1dP0tobacKc8AAAB" +1ms
engine:socket sending packet "open" ({"sid":"WECN1dP0tobacKc8AAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}) +0ms
engine:polling setting request +0ms
engine:socket flushing buffer to transport +0ms
engine:polling writing " �0{"sid":"WECN1dP0tobacKc8AAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}" +1ms
engine:socket executing batch send callback +1ms
socket.io:server incoming connection with id WECN1dP0tobacKc8AAAB +2.5m
socket.io:client connecting to namespace / +1.3m
socket.io:namespace adding socket to nsp / +2.5m
socket.io:socket socket connected - writing packet +1.3m
socket.io:socket joining room WECN1dP0tobacKc8AAAB +0ms
socket.io:client writing packet {"type":0,"nsp":"/"} +1ms
socket.io-parser encoding packet {"type":0,"nsp":"/"} +2.5m
socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +0ms
engine:socket sending packet "message" (0) +1ms
socket.io:socket joined room WECN1dP0tobacKc8AAAB +5ms
engine intercepting request for path "/socket.io/" +140ms
engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=1414498393557-1&sid=WECN1dP0tobacKc8AAAB" +0ms
engine setting new request for existing client +1ms
engine:polling setting request +0ms
engine:socket flushing buffer to transport +0ms
engine:polling writing "�40" +0ms
engine:socket executing batch send callback +0ms
engine upgrading existing transport +39ms
engine:socket might upgrade socket transport from "polling" to "websocket" +0ms
engine intercepting request for path "/socket.io/" +16ms
engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=1414498393618-2&sid=WECN1dP0tobacKc8AAAB" +0ms
engine setting new request for existing client +0ms
engine:polling setting request +0ms
engine:ws received "2probe" +2ms
engine:ws writing "3probe" +0ms
engine:socket writing a noop packet to polling for fast upgrade +100ms
engine:polling writing "�6" +0ms
engine:ws received "5" +4ms
engine:socket got upgrade packet - upgrading +0ms
engine:ws received "2" +25s
engine:socket packet +0ms
engine:socket got ping +0ms
engine:socket sending packet "pong" (undefined) +0ms
engine:socket flushing buffer to transport +0ms
engine:ws writing "3" +0ms
engine:ws received "2" +25s
engine:socket packet +0ms
engine:socket got ping +0ms
engine:socket sending packet "pong" (undefined) +0ms
engine:socket flushing buffer to transport +0ms
engine:ws writing "3" +0ms
engine:ws received "2" +25s
engine:socket packet +0ms
engine:socket got ping +0ms
engine:socket sending packet "pong" (undefined) +0ms
engine:socket flushing buffer to transport +0ms
engine:ws writing "3" +0ms
engine:ws received "2" +25s
engine:socket packet +0ms
engine:socket got ping +0ms
engine:socket sending packet "pong" (undefined) +0ms
engine:socket flushing buffer to transport +0ms
engine:ws writing "3" +1ms
我没有看到任何确认传输升级的日志消息。乒乓球消息也在不断发生。
这是否意味着建立了websocket传输?
答案 0 :(得分:2)
是的,它使用polling first and then upgrades to websocket。我确定如果您使用浏览器连接或使用wireshark,您会看到来自服务器的“HTTP / 1.1 101 Switching Protocols”消息。 你还可以在日志中看到“engine:ws”,这意味着websocket正在运行。 如果您仍然不确定是否也可以打印出传输类型(例如断开连接)。这是服务器端代码(socket.io 1.1.0):
socket.on('disconnect', function () {
console.log(socket.id + ' disconnect ('+ socket.client.conn.transport.constructor.name +')';
});