Socket.io reverting to XHR / JSONP polling for no apparent reason

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

I think Socket.IO should choose The best method to find connection with the server in the series ,

  Websocket ,    FlashSocket     and then JSONP 

but my server which is running socket.io 0.7.7 on the top of node 0.4.9 (on windows compiled with cygwin) goes to XHR/JsonP polling without any apparent reason. I have checked on all ports from 80 - 89 just to make sure , and the problem remains the same all the time.

I also checked for console logs in both the sides. Firebug Gives No error just shows me the XHR get requests instead.

and On the Server Console it gives me :

   info - socket.io started    debug - client authorised  // i dunno why this is occuring though    info - handshake autorised 154845454664764    setting request Get/socket.io/1/xhr-polling/154845454664764    debug - setting poll timeout 

. . . and so on Any reason in mind guys ??

回答1:

You may be using a version of Firefox that has WebSockets disabled.

Warning: Among other things, a key reason WebSockets is currently disabled by default in Firefox 4 and 5 is the discovery of a security issue in the protocol's design. Using WebSockets in those versions of Firefox in a production environment is not recommended at this time. If you still wish to experiment with WebSockets, you may do so by opening about:config and setting the network.websocket.enabled preference to true. You will also need to set the network.websocket.override-security-block preference to true in order to allow initializing a WebSocket connection.



回答2:

Firefox does have websockets disabled. Standard socket.io does not have flashsocket so you have to add it to your configuration =>

io.set('transports', [                     // enable all transports (optional if you want flashsocket)     'websocket'   , 'flashsocket'   , 'htmlfile'   , 'xhr-polling'   , 'jsonp-polling' ]); 

Then it should work just fine.


debug - client authorised  // i dunno why this is occuring though 

socket.io can do authorization.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!