哪些 TCP 协议可用于客户端到客户端的通信?
很多时候,客户要求其 Web 应用程序具有即时消息 (IM) 和其他客户端到客户端 (P2P) 通信等功能。 通常,这在普通网络浏览器中是如何完成的? 例如,我看过 Google Wave(和 Gmail)的演示,它们能够从常规浏览器发送即时消息。 这是通过 HTTP 实现的吗? 或者 XmlHttpRequest (AJAX) 是否为此类通信提供必要的后端?
最重要的是,我想知道服务器如何“唤醒”远程客户端,比如说发送即时消息? 或者客户端是否必须不断“轮询”消息服务器以获取新的 IM?
Manytimes clients ask for features like instant messaging (IM) and other client-to-client (P2P) communication for their web apps. Typically how is this done in normal web browsers? For example I've seen demos of Google Wave (and Gmail) that are able to IM from a regular browser. Is this via HTTP? Or does XmlHttpRequest (AJAX) provide the necessary backend for such communication?
More than anything I wonder how can a server "wake up" the remote client, lets say for sending an IM? Or does the client have to keep "polling" the message server for new IMs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,浏览器将轮询服务器以获取新消息。 为了提高效率,通常采用的一种方法是 '长轮询'(另请参阅此链接) - 服务器如果有任何内容立即响应; 否则,它会等待,使连接保持打开状态一段时间。 如果有消息传入,它会立即唤醒并发送消息,否则它会在几十秒后返回“不,请回来查看”。 客户端立即重拨以返回长轮询状态。
Typically the browser will poll the server for new messages. One approach that is often done to make this more efficient is the 'long poll' (see also this link) - the server responds immediately if it has anything; otherwise, it waits, keeping the connection open for a while. If a message comes in, it immediately wakes up and sends it, otherwise it comes back with a 'nope, check back' after a few tens of seconds. The client them immediately redials to go back into the long-polling state.