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 开发者_如何学Pythonsubmit 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.
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.
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.
精彩评论