javascript:监听服务器

发布于 2025-01-04 19:50:45 字数 174 浏览 3 评论 0原文

在像 collabedit 这样的工具中,当我检查 fiddler 中的流量时,我发现没有从客户端到服务器的轮询。然而,当某个客户端将新数据写入服务器时,另一个客户端“神奇地”知道并请求服务器更新。如果不不断轮询,这是如何实现的?

In tools like collabedit, when I inspect traffic in fiddler I see no polling from clients to server. However when some client writes new data to server, the other "magically" gets to know that and asks the server for update. How is this achieved without constant polling?

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

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

发布评论

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

评论(1

つ可否回来 2025-01-11 19:50:45

这是通过长轮询实现的。

该代码向 http://collabedit.com/ot/wait 发送请求。
在有新数据可用之前,服务器不会响应。当新数据可用时,服务器会发送响应,该响应由代码处理。
然后,重复该循环。

因此,当页面打开时,始终与该网站建立连接。

This is achieved through long polling.

The code sends a request to http://collabedit.com/ot/wait.
The server doesn't respond until new data is available. When new data is available, the server sends a response, which is handled by the code.
Then, the cycle is repeated.

So, when the page is open, there's always a connection with the site.

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