views:

2602

answers:

3

All HTTP responses require the client to initiate them, even those made using AJAX. But GMail's chat feature is able to receive messages from other users, even when I'm just sitting in my comfy computer chair watching but not interacting with the browser. How did they do it?

+3  A: 

As you rightfully pointed out, HTTP requires data to be 'pulled' by the client. Gmail can still 'pull' data from the server by using a timer to trigger the HTTP operation instead of requiring the user to click something. So, it may seem to be auto, but it is still client initiated.

sybreon
I've heard they use comet. It's not a client request AFAIK
Pablo Fernandez
I see. Learned something new today. Thanks!
sybreon
Comet is still client-initiated AFAIK - it's just that the server keeps the connection open until it's got something interesting to say instead of immediately returning a response.
Jon Skeet
And indeed reading through the wikipedia article, it's pretty clear that for all current implementations, the client initiates the connection. It's hard to see how else it could work, to be honest.
Jon Skeet
I guess it depends on how it is viewed. At the TCP layer, it is definitely client pull. However, at the app layer, it depends. If it sends something down that triggers a javascript in the client, is it still client pull? If it immediately sends another trigger, is it still client pull?
sybreon
+23  A: 

That tech is known as "comet", but also as "server push", "reverse ajax", etc.

It's about pushing data from the server to the browser, keeping an http connection alive. Find more info on it on the wikipedia article (English version).

Also here's a pretty good presentation with Joe Walker from DWR, where he talks about comet.

Pablo Fernandez
do you know which method Gmail uses? Hidden IFrame, XMLHttpRequest?
chat
@chat view source?
Rex M
Perhaps link to the English version of Wikipedia?
Frank Crook
@Frank Sorry! My locale betrays me :D, thanks jon for the correction, I'll double check next time.
Pablo Fernandez
I haven't looked at comet in awhile, but last time I looked into it the issue was that apache really can't hold that many connections open at once. So if you were to implement comet you would need a lot more servers then you would otherwise need.
thirsty93
@thirsty in the presentation linked above, the author states that when apache2 was under development, comet was not as known and therefore it's support is poor. I believe this will improve in next releases if comet caches up a bit more.
Pablo Fernandez
+4  A: 

Yep Comets is correct. Google Web Toolkit Applications by Ryan Dewsbury explains how to create a Comets based Instant Messenger application in chapter 9.

Ankur