长轮询和使用Comet之间有区别吗? [英] Is there a difference between long-polling and using Comet

查看:98
本文介绍了长轮询和使用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.

推荐答案

一些 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.

这篇关于长轮询和使用Comet之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆