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

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

问题描述

关于 JavaScript &PHP WebSocket TCP 数据包聚集,如下所示.

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

出于某种原因,当在我的 VPS 上快速发送数据包时,或通过指向我的 IP 地址的域访问我的本地主机时,多个数据包会聚集在一起.在这个例子中,我试图每秒流式传输 20 个(@100byte)数据包.在服务器端,它们确实以稳定的速率发送出去,恰好每 50 毫秒发送一次,每秒发送 20 次.但是,当它们到达客户端时,客户端仅每 1/4 秒处理一次新消息.导致只能以每秒 4 个左右的速率接收新数据包...

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...

是什么导致了这种数据包聚集在一起?当一切都通过 localhost 时不会发生此问题.更奇怪的是,它在 iPhone 的 iOS Mobile Safari 上流畅地传输,完全没有问题.但是,它在 PC Safari 上根本不起作用(因为我还没有将其设置为与旧的 Hixie-76 WebSocket 格式一起正常工作,我假设 Mobile Safari 已经在使用更新的 RFC 6455 或更新的 JavaScript编译器)我尝试了多家托管公司,每次都得到完全相同的结果.

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.

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

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

当前接收到的数据包每次会跳大约 5 个,因为每 1/4 秒一次接收 5 个数据包.但是,我见过可以发送持续、快速的数据包流的示例.是什么导致这种聚集在一起/数据包相互等待?

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?

编辑:这与Nagle 的算法有关,收集 &一起发送小包?我将努力尝试在 PHP 中绕过它.即使在 PHP 中设置了这个 TCP_NODELAY,问题仍然存在.为什么它适用于 iPhone 而不适用于 PC 仍然让我失望......
编辑:在注册表中将 TCPNoDelay 和 TcpAckFrequency 设置为 1 可以解决这个问题,但我不能指望每个用户都这样做.必须有客户端,面包&黄油 JavaScript 方式.

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.

我如何才能复制 node.js 的socket.setNoDelay(true)",不使用 node.js?

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

推荐答案

这就是 TCP.它通过节省 IP 数据包来帮助您.部分原因是Nagle算法,部分原因也可能是中间网络造成的.

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天全站免登陆