javascript:监听服务器
在像 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是通过长轮询实现的。
该代码向 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.