socket.io - XHR 轮询 vs flashsocket 和 websocket [英] socket.io - XHR polling vs flashsocket and websocket

查看:54
本文介绍了socket.io - XHR 轮询 vs flashsocket 和 websocket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 node.js 和 socket.io.我对 socket.io 的连接速度有问题.在 Internet Explorer 和 Opera 中,我的连接速度有问题.- 当我使用 flashsocket 或 websocket 时.当我使用传输轮询模式时,XHR 连接速度很快 - 在所有浏览器(IE、FF、Chrome、Opera)中.

I use node.js and socket.io. I have a problem with the connection speed with socket.io. In Internet Explorer and Opera I have a problem with the connection speed. - When I use flashsocket or websocket. When I use the mode of transport-polling XHR connection is fast - in all browsers (IE, FF, Chrome, Opera).

传输方式 - XHR-polling 和 flash/websocket 有什么区别?最好的交通方式是什么?socket.io如何优化连接速度?

What is the difference between the mode of transport - XHR-polling and flash / websocket? What is the best mode of transportation? How to optimize the connection speed is socket.io?

感谢您的建议!

推荐答案

如果 Web 浏览器之间的总体连接速度随着时间的推移而有所不同,我会感到惊讶,但您会看到初始连接延迟的原因在 Internet Explorer 和 Opera 中,原生 WebSocket 支持不可用,因为默认情况下它已被禁用.因此,如果您选择 FlashSocket,则需要在建立连接之前下载额外的 Flash 对象(SWF 文件).

I'd be surprised if the general speed of the connection over time was different between web browsers, but the reason you'll see a delay in the initial connection in Internet Explorer and in Opera is that native WebSocket support is not available as it's been disabled by default. So, if you choose FlashSocket then an additional Flash object (SWF file) will need to be downloaded before a connection is established.

WebSockets 在 IE10 和 Opera 中被引入,它们可用,但默认情况下被禁用.

WebSockets are being introduced in IE10 and in Opera they are available, but disabled by default.

传输方式 - XHR-polling 和 flash/websocket 有什么区别?

What is the difference between the mode of transport - XHR-polling and flash / websocket?

  • XHR 轮询 - 参见 http://en.wikipedia.org/wiki/Push_technology#Long_polling
  • FlashSocket 连接 - 使用 Flash Socket 对象建立与 WebSocket 服务器的连接并使用 WebSocket 协议进行通信.这意味着 Flash 和 JavaScript 之间存在交互,还意味着需要下载额外的 Flash 对象(SWF 文件).
  • 最好的交通方式是什么?

    What is the best mode of transportation?

    WebSockets 适用于任何原生支持它的 Web 浏览器(Chrome、Firefox、Safari).如果 Flash 对象(SWF 文件)在浏览器缓存中,那么连接应该很快.如果不是,那么就会有延迟.XHR 长轮询是一个很好的解决方案,可以跨浏览器工作,但也有负面影响:

    WebSockets for any Web Browser that natively supports it (Chrome, Firefox, Safari). If the Flash object (SWF file) is in the browser cache then connection should be fast. If it's not then there will be a delay. XHR Long-Polling is a good solution and will work cross browser but there are negatives:

    • 在轮询请求之间,显示的数据可能已过时(过时).
    • 与 WebSocket 使用的单个 TCP 连接相比,这是一种效率较低的连接方法,因为 HTTP 长轮询使用多个连接来模拟双向功能
    • HTTP 有开销,这意味着根据请求和每个后续请求发送额外的标头信息.

    socket.io如何优化连接速度?

    How to optimize the connection speed is socket.io?

    (我对 socket.io 很陌生,这只是一个建议)

    (I'm pretty new to socket.io to this is just a suggestion)

    我会查看配置 Socket.io 文档 看看你是否可以根据连接的浏览器有条件地设置transsports.根据您的经验,这可能是:

    I'd look at the configuring Socket.io docs and see if you can conditionally set the transports based on the browser that is connecting. Based on your experiences this could be:

    • Chrome、Firefox、Safari - WebSockets
    • IE、Opera - XHR 轮询

    这篇关于socket.io - XHR 轮询 vs flashsocket 和 websocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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