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?
59
votes
Question hijack: what kind of AJAX polling strategy does Gmail use to implement the chat client?
- Jimmy
wow you practically re-wrote the question.
- Pablo Fernandez
@Pablo: yeah... pretty sure this is what he was asking, but didn't figure it out 'till i'd already answered, so i wanted to clean it up 'fore someone else made the same mistake.
- Shog9
@Pablo: Yes he did rewrite the question. It made zero sense in the original post.
- Samuel
This Comet thingy sounds like the right answer, but I have also done something where a jQuery loop just keeps checking the server for updates, like chat updates. No user intervention required. Still it seems there is existing technology for this, not worth re-inventing.
- Tim
3 Answers
42
votes
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.
8
votes
5
votes
Yep Comets is correct. Google Web Toolkit Applications by Ryan Dewsbury explains how to create a Comets based Instant Messenger application in chapter 9.