socket.io doens't work with transports: [ 'xhr-polling' ]

牧云@^-^@ 提交于 2019-12-10 15:17:37

问题


I'm trying to test fallback to polling in socket.io, in order to verify that my app works with clients that don't support websockets for whatever reason.

I am using the very basic server/client example for Express 4. It works fine with:

// client-side
var options = {
   transports: [ 'xhr-polling', 'websocket' ]
};

var socket = io.connect('http://localhost:8080', options);
socket.on('news', function (data) {
  console.log(data);
  socket.emit('my other event', { my: 'data' });
});

However if I remove the 'websocket' from the transport, nothing happens on the client end- no error, no events, nothing. On the server side I see only:

Tue, 03 Mar 2015 16:45:49 GMT socket.io:server serve client 304

回答1:


I popped open the source and found that socket.io.js is now checking for the string polling instead of xhr-polling. So this works:

var options = {
   transports: [ 'polling' ]
};


来源:https://stackoverflow.com/questions/28837558/socket-io-doenst-work-with-transports-xhr-polling

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