socket.io - XHR 轮询与 flashsocket 和 websocket
我使用node.js 和socket.io。我的 socket.io 连接速度有问题。在 Internet Explorer 和 Opera 中,我遇到连接速度问题。 - 当我使用 flashsocket 或 websocket 时。当我使用传输轮询模式时,XHR 连接速度很快 - 在所有浏览器(IE、FF、Chrome、Opera)中。
传输模式 - XHR-polling 和 flash/websocket 之间有什么区别?最好的交通方式是什么? socket.io如何优化连接速度?
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).
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 Web 浏览器之间的连接速度随着时间的推移有所不同,我会感到惊讶,但您会在 Internet Explorer 和 Opera 中看到初始连接延迟的原因是原生 WebSocket 支持不可用,因为它已经默认禁用。因此,如果您选择 FlashSocket,则在建立连接之前需要下载额外的 Flash 对象(SWF 文件)。
WebSockets 在 IE10 中引入,在 Opera 中可用,但默认情况下禁用。
适用于任何本机支持它的 Web 浏览器(Chrome、Firefox、Safari)的 WebSocket。如果 Flash 对象(SWF 文件)位于浏览器缓存中,则连接速度应该很快。如果不是的话就会有延迟。 XHR 长轮询是一个很好的解决方案,可以跨浏览器工作,但也有缺点:
(我对 socket.io 还很陌生,这只是一个建议)
我会看看 配置 Socket.io 文档,看看是否可以根据连接的浏览器有条件地设置
传输
。根据您的经验,这可能是: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 are being introduced in IE10 and in Opera they are available, but disabled by default.
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:
(I'm pretty new to socket.io to this is just a suggestion)
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:要减少连接时间,可以尝试使用“连接超时”参数来减少连接超时(默认为 10 秒)。
例如,要将连接超时减少到 1 秒:
To reduce the time of connection, you can try to reduce the connect timeout (which is 10 seconds by default) using the "connect timeout" parameter.
For example, to reduce the connect timeout to 1 second: