长轮询和使用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.