长轮询和使用 Comet 之间有区别吗
我正在实现一个需要实时更新的系统。我一直在研究某些场景,其中包括彗星。实现这一点我认为这与传统的长轮询没有任何不同。
在这两种情况下,您都必须发送请求,然后服务器发回响应。在浏览器中,您解释响应,然后启动新请求。
那么,如果在这两种情况下我都需要打开和关闭连接,为什么我应该使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一些 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.
正如 Marcelo 所提到的,Comet 通常用于描述“HTTP 流式传输”的任何技术”,包括长轮询。在某些情况下,Comet 还可能更具体地引用Bayeux 协议。例如, jQuery Comet 插件就是这个协议。来自贝叶网站:
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:
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.
Comet 是各种异步更新技术的总称,长轮询只是其中之一。
Comet is an umbrella term for a wide range of asynchronous update techniques, of which long-polling is just one.
如果你想推送而不是拉取,你可以使用JPE。
If you want to push insteal of pulling, you can use JPE.