Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between long-polling and using 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.

like image 877
Saif Bechan Avatar asked Apr 03 '10 09:04

Saif Bechan


People also ask

What is polling and Comet?

Comet Model Streaming: Events are pushed from server to client over a single persistent connection, and are usually processed inside a hidden iframe on the page or via XMLHttpRequest. Long Polling: The browser polls the server for new events with a persistent request that is held open until it gets a response.

What is long polling used for?

HTTP Long Polling is a technique used to push information to a client as soon as possible on the server. As a result, the server does not have to wait for the client to send a request. In Long Polling, the server does not close the connection once it receives a request from the client.

Is long polling better than WebSockets?

Long polling takes HTTP request/response polling and makes it more efficient, since repeated requests to a server wastes resources. For example, establishing a new connection, parsing the HTTP headers, a query for new data, response generation and delivery, and finally connection closure and clean up.

What is Comet in real time reaction?

Comet is a web application model in which a long-held HTTPS request allows a web server to push data to a browser, without the browser explicitly requesting it. Comet is an umbrella term, encompassing multiple techniques for achieving this interaction.


2 Answers

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.

like image 138
T.J. Crowder Avatar answered Oct 03 '22 04:10

T.J. Crowder


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.

like image 43
Jørn Schou-Rode Avatar answered Oct 03 '22 04:10

Jørn Schou-Rode