Nirvana JavaScript : Comet LongPolling Delivery Mode

An Introduction to Comet LongPolling

LongPolling is a variation of the traditional polling technique. In traditional polling, a client sends requests on a regular basis to the server attempting to pull any new data available on the server. If there are no events on the server an empty response is returned and after a specified delay the client sends a new request.

LongPolling sends requests to the server in much the same way as traditional polling. In a LongPoll implementation however if the server has no data to push it holds the request up until the point where new data is available or the request times out. Once the server sends a LongPoll response the client typically initiates a new request immediately.

As the server usually holds a LongPoll request at all times from the client. It is able to asynchronously push data to the client by providing it with a response.

Comet LongPolling in Nirvana

The LongPolling delivery mode is supported by Nirvana's JavaScript API and can be used by all browsers. In addition to LongPolling, WebSocket and Forever IFrame delivery modes are also offered by the API.

LongPolling is a desirable option when the implementation must support older browser versions, or also when requests must traverse proxy servers which may not be configurable by those developing the application. Other delivery modes often require newer browsers or unobtrusive end-to-end connections.

A Nirvana JavaScript client can communicate with a server using the LongPolling delivery mode by specifying the following configuration when starting a session:

        NirvanaSession.start({
            ...
            protocolSelection : ["longpollcomet"]
        });