套接字。io doens不使用传输方式:['xhr-polling']

时间:2022-02-01 19:42:54

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.

我试着测试在套接字的轮询。io,为了验证我的应用程序是否与不支持websockets的客户一起工作。

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

我正在使用非常基本的服务器/客户端示例来实现Express 4。它将正常工作:

// 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:

但是,如果我从传输中删除“websocket”,那么在客户端没有发生任何事情——没有错误,没有事件,没有任何事情。在服务器端,我只看到:

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

1 个解决方案

#1


9  

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:

我打开了源代码,发现了socket.io。js现在检查字符串轮询而不是xhr-polling。所以这个工作原理:

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

#1


9  

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:

我打开了源代码,发现了socket.io。js现在检查字符串轮询而不是xhr-polling。所以这个工作原理:

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