WebSocket TCP数据包聚集在一起? [英] WebSocket TCP packets clumping together?

查看:295
本文介绍了WebSocket TCP数据包聚集在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于JavaScript&由于某些原因,当在我的VPS上快速发送数据包,或通过指向我的IP地址的域访问我的本地主机时,多个数据包将聚集在一起。我正在尝试流式传输20个(@ 100byte)数据包。在服务器端,它们确实以稳定的速度发送,正好每隔50ms发送一次,每秒钟发送20次。
但是,当他们到达客户端时,客户端仅处理每秒钟1/4的新消息。导致新数据包仅以每秒4次的速度接收...



是什么导致这些数据包聚集在一起?当一切通过本地主机时,不会发生此问题。更值得一提的是,它在iPhone的iOS移动版Safari上流畅播放,完全没有问题。但是,它在PC Safari上完全不起作用(因为我没有把它设置为使用旧的Hixie-76 WebSocket格式正确工作,我假设Mobile Safari已经使用了较新的RFC 6455或更新的JavaScript编译器)我尝试了多个托管公司,每次都有完全相同的结果。



请参阅下面的示例,托管在InMotion的VPS上:
http://www.hovel.me/script/serverControl.php



(点击左侧的[连接],然后点击右侧的[查看游戏])。



每次收到的当前数据包将大约跳5次,因为每1/4秒一次接收每5个数据包。但是,我已经看到了可以发送恒定,快速数据包流的示例。
是什么导致这个聚集在一起/数据包相互等待?



编辑:这与< a href =http://en.wikipedia.org/wiki/Nagle%27s_algorithm =noreferrer> Nagle的算法,它收集&一起发送小包?我将努力在PHP中绕过这一点。
即使在PHP中设置了此TCP_NODELAY,问题仍然存在。为什么它可以在iPhone上运行,但不能在PC上运行,仍然让我失望...

编辑:在注册表中设置TCPNoDelay和TcpAckFrequency为1修复了这个问题,期望每个用户都这样做。必须有客户端,面包和咖啡。黄油JavaScript的方式。



我如何能够复制node.js' socket.setNoDelay(true),而不使用node.js? 解析方案

这是TCP。它通过节省IP包帮助你。部分原因是由于Nagle算法,但部分原因也可能是由中间网络引起的。


Concerning JavaScript & PHP WebSocket TCP packet clumping, with example below.

For some reason, when sending packets quickly on my VPS, or accessing my localhost through a domain pointing at my IP address, multiple packets will clump together. I am trying to stream, for this example, 20 (@100byte) packets per second. On the servers end, they ARE indeed being sent out at a steady rate, exactly every 50ms, making 20 per second. However, when they get to the client, the client only processes new messages about every 1/4th of a second. Causing new packets only to be received at a rate of 4 per second or so...

What is causing this clumping of packets together? This problem does not occur when everything through localhost. What's weirder is that it streams smoothly on iPhone's iOS Mobile Safari, with no problem at all. BUT, it doesn't work at all on PC Safari, (because I haven't set this up to work correctly with the old Hixie-76 WebSocket format, I'm assuming Mobile Safari is already using the newer RFC 6455 or newer JavaScript compiler) I have tried multiple hosting companies, with the exact same results each time.

See the example below, hosted on InMotion's VPS: http://www.hovel.me/script/serverControl.php

(Click [Connect] on the left, then [View Game] on the right).

The current packet received will jump about 5 every time, as each 5 packets are received at once, every 1/4th of a second. However, I've seen examples that can send a constant, quick stream of packets. What causes this clumping together / packets to wait for each other?

EDIT: This HAS to be something to do with Nagle's algorithm, which collects & sends small packets together? I'll work towards trying to bypass this in PHP. Even with this TCP_NODELAY set in PHP, the problem still stands. Why it works on an iPhone but not a PC is still throwing me off...
EDIT: Setting TCPNoDelay and TcpAckFrequency to 1 in the registry fixes this, but I can't expect every user to do that. There must be a client-side, bread & butter JavaScript way.

How can I have functionality replicating node.js' "socket.setNoDelay(true)", without using node.js?

解决方案

That's TCP. It is helping you by economizing on IP packets. Part of it is due to the Nagle algorithm but part of it may also be caused by the intermediate network.

这篇关于WebSocket TCP数据包聚集在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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