我需要针对IE使用jsonp-polling,对于Firefox使用xhr-polling,所以我
试图像这样在客户端定义传输类型:

    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
            var socket = io.connect(VG.NODE_SERVER_URL,{
                    transports:['xhr-polling']
            });
    } else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
            var socket = io.connect(VG.NODE_SERVER_URL,{
                    transports:['jsonp-polling']
            });
    } else {
            var socket = io.connect(VG.NODE_SERVER_URL);
    }

我在Firefox上对其进行了测试,并在socket.io-client lib上添加了日志记录。


https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1509

option.transports是["xhr-polling", "flashsocket", "htmlfile","xhr-polling", "jsonp-polling"],这是正确的。但是,在

https://github.com/LearnBoost/socket.io-client/blob/master/dist/socket.io.js#L1679

我不知道为什么传输方式更改为["htmlfile", "jsonp-polling", "xhr-polling"],其顺序与我的顺序相同
在服务器端定义。

为什么不使用上一个选项?

最佳答案

该错误现已在socket.io 0.9.6版中修复,我可以使用它,并且可以正常工作:

socket = io.connect(HOST_REMOTE, {
    transports: ['xhr-polling']
});

在1.0.0及更高版本中:
socket = io.connect(HOST_REMOTE, {
    transports: ['polling']
});

10-04 14:31