有些用户无法连接到websocket

我正在使用socket.io.Some用户发送消息给我'我无法发送消息为什么'我研究了这个问题,猜测防火墙或防病毒阻塞websocket.If浏览器不支持websocket,socket.io自动切换到xhr轮询,这是没有问题的。但是,如果浏览器支持websocket和防病毒或防火墙阻止websocket,socket.io不切换到xhr,并且用户不能发送消息。如何解决这个问题?

这里是一个websockettesting报告的用户

http://websocketstest.com/result/244711

Websocket的支持是好的,数据接收是否定的。

您可以将Socket.IO设置为仅在configuration中使用XHR轮询:

io.configure(function () { io.set("transports", ["xhr-polling"]); }); 

请参阅官方文档中的configurationSocket.IO 。

我发现很多用户最终无法与socket.io成功连接。 与其试图不断地诊断它,我已经开始构build我的应用程序,以便轻松地回退到ajax。 实际上,我可以将useSocketIO的环境variables改为false,整个网站聊天,小费,图片共享都会回退到ajax。 这并不能解决潜在的问题,但是为丢失的数据没有被传输节省了很多的麻烦。

伪代码在客户端上

 # check that I have a socket object if socket != null # if not connected, try to reconnect if !socket.connected and !socket.connecting attemptResetOfSocketIO() # if now connected, send socket message if socket.connected or socket.connecting sendSocketMessage() else # not connected, send via ajax sendAjaxMessage() else # no socket object, send via ajax sendAjaxMessage()