Socket.IO failed: Error during WebSocket handshake:

    在node安装了Socket.IO,做demo时报错

    WebSocket connection to 'ws://localhost:8999/socket.io/?EIO=3&transport=websocket&sid=D0fxLuPwjHWgYSI7AAAB' failed: Error during WebSocket handshake: Unexpected response code: 400

 

    WebSocket 握手时发生错误,诡异的是我前端页面没有关闭,重启服务器node app.js后socket重新连上了

    经多次测试验证,只有登陆进入才会报错,但是之后Socket 是处在连接状态的如图,连接不是很稳定,cookie也可以获取到。重启之后可以socket自动连上。

 

    这就奇怪了。。折腾了许久,另外写了个更简单的demo, 只要必要的express和socket.io, 发现没问题。

    然后排查,最后找到了这货

 

 

    express-status-monitor

    基于socket.io和chat.js的服务器监控器

    可能会存在冲突,把这个注释之后,可以了!

    然后在express-status-monitor, 找到了原因:

    If you're using socket.io in your project, this module could break your project because this module by default will spawn its own socket.io instance. To mitigate that, fill websocket parameter with your main socket.io instance as well as port parameter.

posted on 2017-02-28 20:10  断剑重铸  阅读(8291)  评论(0编辑  收藏  举报