marstone
marstone

Reputation: 704

Long Polling client-side "Time Gap" Between 2 Pollings

Assume I have a server support client side long polling. then my client-side code is like this:

var polling = function() {
    $.ajax({
        url: "/polling"
    }).done(function(data) {
        // polling again
        polling();
        // process the pushed data
        ...
    });
}
polling();

this should work when i wanna push something to the client while the client continuously polling to "/polling".

however, you may notice that there are "time gap" between the client received a pushed data and next polling reaches the server. data in this "time gap" would be lost.

there are kinds of server side workarounds to avoid this problem. but i want to know if there are any workarounds in the client-side? such as: * could the client keeps the long polling request always connected? i find Gmail should do some tricks like this. i chat in gtalk but don't see the "/bind" request interrupts. * should ajax receives in-complete data while transfering? then the connection can be connected forever. * should websocket works? if so, what can i do without HTML5?

Upvotes: 0

Views: 544

Answers (1)

Dhaivat Pandya
Dhaivat Pandya

Reputation: 6536

You might want to consider something like Pusher, it will make your life much easier when dealing with such things (because they give you a library to handle all of this in a nice package).

Upvotes: 1

Related Questions