2009/4/21 tedd <tedd.sperling@xxxxxxxxx>: > At 5:14 PM +0200 4/21/09, David Négrier wrote: >> >> Here is a quick explanation of what is going on behind the scene: >> >> -snip- >> >> Regards, >> David. > > Thanks -- I think I know what's going on. I've done sufficient ajax to know > what's going on. However, what I don't understand is: > > 1. Detecting who is currently online (i.e., all who are connected to THE > server); > > 2. And then how to send all of them stuff. > > For example, if you have four people connected to the server at the same > time and one sends something, then how do you forward that to each person so > that their screen refreshes accordingly? There are a number of ways to approach this. In essence all Comet does is move that problem from the client to the server which opens up a whole cupboard full of options. The "best" options is probably something like pub-sub in XMPP. In this scenario each connected user "subscribes" to another end point within the XMPP network, which basically means it will receive any messages that end point sends. The end point in the case of chat would be a central phantom user who in turn subscribes to everyone else. Beyond that you have traditional polling of some resource (database, files, etc) or any other mechanism for finding new stuff to send to the client. The client makes the AJAX request and the server holds on to it doing nothing for up to n seconds (in phones case it's 55 seconds). If nothing has been received by then it simply returns an empty response. When something does arrive to be sent the server sends the response and the connection closes. The client then deals with the data it's just received and then starts another connection. Hence the name, long polling. I've had a response from my client and he's happy to open source the whole thing but it needs a bit of work before it's ready for that so it may be a little while before I have something, but I'll be sure to post a link here and on my blog when it's released. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php