长轮询和使用 Comet 之间有区别吗

发布于 2024-08-27 18:11:18 字数 169 浏览 7 评论 0原文

我正在实现一个需要实时更新的系统。我一直在研究某些场景,其中包括彗星。实现这一点我认为这与传统的长轮询没有任何不同。

在这两种情况下,您都必须发送请求,然后服务器发回响应。在浏览器中,您解释响应,然后启动新请求。

那么,如果在这两种情况下我都需要打开和关闭连接,为什么我应该使用 comet。

I am implementing a system where I need real-time updates. I have been looking at certain scenarios and among all was Comet. Implementing this I do not see any way this is different from traditional long-polling.

In both cases you have to send a request, and then the server send a response back. In the browser you interpret the response and then you start a new request.

So why should I use comet if in both cases I need to open and close connections.

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

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

发布评论

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

评论(4

千紇 2024-09-03 18:11:18

一些 Comet 技术并不要求您不断地打开新请求(例如,分块的隐藏 iframe),其想法是保持请求打开并让服务器定期发送数据。但这并不能在所有主要浏览器上都很好地工作,而且不会产生负面副作用(正如一位维基百科贡献者巧妙地指出的那样),因此需要长轮询技术。更多内容请参见链接文章。

Some Comet techniques don't require that you constantly open new requests (the chunked hidden iframe, for instance), the idea being to hold the request open and have the server periodically sending data. But this doesn't work well across all major browsers without (as one Wikipedia contributor delicately put it) negative side-effects, hence the long-polling technique. More in the linked article.

柠檬色的秋千 2024-09-03 18:11:18

正如 Marcelo 所提到的,Comet 通常用于描述“HTTP 流式传输”的任何技术”,包括长轮询。在某些情况下,Comet 还可能更具体地引用Bayeux 协议。例如, jQuery Comet 插件就是这个协议。来自贝叶网站:

从服务器到 Web 客户端的异步消息传递通常被描述为服务器推送。
服务器推送技术与 Ajax Web 应用程序的组合称为 Comet。
CometD 是 Dojo 基金会的一个项目,旨在以多种编程语言提供 Bayeux 协议的多种实现。

Bayeux 尝试使用 Comet 技术标准化发布/订阅协议,允许客户端和服务器端库的供应商创建可互操作的组件。

As mentioned by Marcelo, Comet is usually used to describe any techniques for "HTTP streaming", including long-polling. In some cases, Comet might also refer more specifically to the Bayeux Protocol. For instance, the jQuery Comet plugin is of this protocol. From the Bayeux website:

Delivery of asynchronous messages from the server to a web client is often described as server-push.
The combination of server push techniques with an Ajax web application has been called Comet.
CometD is a project by the Dojo Foundation to provide multiple implementation of the Bayeux protocol in several programming languages.

Bayeux is an attempt to standardize a publish/subscribe protocol using Comet techniques, allowing for vendors of client and server side libraries to create interoperable components.

笙痞 2024-09-03 18:11:18

Comet 是各种异步更新技术的总称,长轮询只是其中之一。

Comet is an umbrella term for a wide range of asynchronous update techniques, of which long-polling is just one.

困倦 2024-09-03 18:11:18

如果你想推送而不是拉取,你可以使用JPE

If you want to push insteal of pulling, you can use JPE.

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