哪些 TCP 协议可用于客户端到客户端的通信?

发布于 2024-07-29 21:16:49 字数 338 浏览 2 评论 0原文

很多时候,客户要求其 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 技术交流群。

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

发布评论

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

评论(1

屋顶上的小猫咪 2024-08-05 21:16:51

通常,浏览器将轮询服务器以获取新消息。 为了提高效率,通常采用的一种方法是 '长轮询'(另请参阅此链接) - 服务器如果有任何内容立即响应; 否则,它会等待,使连接保持打开状态一段时间。 如果有消息传入,它会立即唤醒并发送消息,否则它会在几十秒后返回“不,请回来查看”。 客户端立即重拨以返回长轮询状态。

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.

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