问题描述
我正在尝试在socket.io中测试回退到轮询,以验证我的应用程序可与出于任何原因不支持websocket的客户端一起使用.
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.
我正在为Express 4使用非常基本服务器/客户端示例. >
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' });
});
但是,如果我从传输中删除"websocket",则客户端上什么也不会发生-没有错误,没有事件,也没有任何事情.在服务器端,我只能看到:
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
推荐答案
我突然打开源代码,发现socket.io.js现在正在检查字符串polling
而不是xhr-polling
.这样就可以了:
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' ]
};
这篇关于socket.io不适用于传输:['xhr-polling']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!