Socket.io reverting to XHR / JSONP polling for no

2020-06-30 03:12发布

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 ??

2条回答
一夜七次
2楼-- · 2020-06-30 03:37

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.

查看更多
在下西门庆
3楼-- · 2020-06-30 03:49

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.

查看更多
登录 后发表回答