Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

my own long polling implementation compared to facebook and gmail

For days I have been experimenting with long polling/comet implementation for my site. I got the basic idea of how it works, this is where i run some tests.

On the other hand, I have been observing(firebug) how gmail and facebook implement long polling. What I noticed with gmail is that the ajax request does not continuously follow right after the current request expires, but it waits for several seconds/minutes before it fires the next one.

I played with it some more. I tried to login with gmail account A in firefox and gmail account B in chrome. I waited when the current ajax poll finishes and then I sent an email from account B to A. I was expecting that account A won't receive it until the next poll, but to my surprise Account A directly received it right after I hit the submit button.

How does gmail do this with long polling ?

If you try to visit my site and click on the Run button and open firebug, you can see that ajax spinner is always running. when the server responds with data, it requests the server again.

like image 907
n3rfd Avatar asked Sep 26 '11 04:09

n3rfd


2 Answers

I think your assumption that Gmail uses (only) long polling is incorrect. According to this question (and the answer) it uses forever frame, and forever XHR. See also BrowserChannel, which they use for Gmail Chat.

like image 53
Matthew Flaschen Avatar answered Oct 20 '22 02:10

Matthew Flaschen


Take a look at WebSync from Frozenmountain or SignalIR which take the work out of the backed pieces. I can vouch for websync as I use it everyday, but been hearing good things about signalir.

like image 28
Steve Sloka Avatar answered Oct 20 '22 00:10

Steve Sloka