在客户端定义传输类型 [英] Define transport types on the client side

查看:132
本文介绍了在客户端定义传输类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用jsonp-polling for IE和xhr-polling for Firefox,所以I
尝试在客户端定义类型的传输,如下所示:

I need to use jsonp-polling for IE, and xhr-polling for Firefox, so I tried to define types of transports on the client side like this:

    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-

I tested it on Firefox and added logging on socket.io-client lib. At

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

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

the option.transports is ["xhr-polling", "flashsocket", "htmlfile", "xhr-polling", "jsonp-polling"], which is right. However, at

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

我不知道为什么传输变为 [htmlfile,jsonp-
polling,xhr-polling]

I do not know why the transports change to ["htmlfile", "jsonp- polling", "xhr-polling"], which has the same sequence as what I defined on server side.

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

Why doesn't it use the previous option?

推荐答案

该bug现在固定在socket.io版本0.9.6中,我可以使用它,它工作正常:

The bug is now fixed in socket.io version 0.9.6, I can use this and it works fine :

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

在版本1.0.0及以上版本中:

In version 1.0.0 and above:

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

这篇关于在客户端定义传输类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆