iOS Safari WebSockets:短时间间隔发送消息时存在巨大延迟

发布于 2024-12-25 22:03:23 字数 300 浏览 3 评论 0原文

我刚刚发现在 iOS Safari (iOS 5.0.1) 上使用 websockets 是一件非常烦人的事情。当以非常接近的间隔发送两条消息时(例如 30 - 40 毫秒,例如,在按钮上鼠标按下时发送一条消息,在鼠标松开时发送一条消息),这两条消息以 200 到 300 毫秒的间隔到达服务器。 例如,这使得在 iOS 上使用 WebSockets 来制作远程控制器真的很痛苦……

我担心我知道答案,但是有什么办法可以让它更好地工作吗?这似乎是 Safari 的 Websockets 实现中的一个错误,但它也可能来自 WiFi 实现(我几乎不这么认为......)?

I just found a very annoying thing about using websockets on iOS Safari (iOS 5.0.1). When sending two messages at very close interval (think 30 - 40ms, for example, sending a message at mousedown on a button and one on mouseup) the two messages arrive at 200 to 300ms of interval on the server.
This makes using WebSockets on iOS really painful for making a remote controller for example...

I'm affraid I know the answer, but is there anyway to make it work better ? It seems like it's a bug in the Websockets implementation of Safari but could it also be coming from the WiFi implementation (I hardly think so...) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光飞翔i 2025-01-01 22:03:23

我刚刚发现了某种解决方法,并且 Safari Mobile 的 websockets 实现的行为比我已经发现的更奇怪。

在进行一些 ping 测试来验证我的理论时,我意识到我不再遇到问题了。然后我用原来的代码再次测试,又遇到了同样的问题。

然后我意识到与 ping 测试相比,我的代码发生了哪些变化:服务器从不向客户端发送任何内容。因此,每当我的服务器收到来自 iPhone 的消息时,他就会向 iPhone 发回一条消息。这样,延迟就会消失。这真的很奇怪,可能需要采取一些措施来解决这个问题,但与此同时,这会起作用......

I just found out some kind of workaround, and that the websockets implementation of Safari Mobile behaves even weirder than what I already found out.

While making some ping tests to validate my theory, I realised that I didn't have the problem anymore. Then I tested again with my original code and I had the same problem again.

Then I realised what changed in my code, compared to the ping test : the server never sends anything to the client. So, whenever my server receives a message from the iPhone, he sends a message back to it. That way, the latency disappears. It's really weird and there's probably something to be done to fix that issue, but in the meantime, this will do...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文