views:

232

answers:

1

Current Project Setup

I'm prototyping an online chat system similar to Facebook chat, using PHP, AJAX, a lot of jQuery, and a MySQL database. I'm developing on an Apache Server 2.2.14 (all local... working on a MacBook Pro 10.6.4).

The way I listen for incoming chats and check for new messages in an existing chat is by doing:

setTimeout(function() { listenForIncomingChat() }, 500);
setTimeout(function() { checkForIncomingMessages( ...params... ) }, 500);

... so by doing the setTimeout() makes sure these functions are always running. Depending on how many chat windows I have open, Firebug's console can go crazy with POSTs to the server.

Some Research

Now, I have heard a lot about Comet Programming and that this is the way to open a long-lived HTTP connection with the server. WebSockets for HTML5 is probably even better, but since that is not in full swing, I'll stick with what works now. So there are several ways to develop with the Comet style: Streaming (hidden iFrame, XMLHttpRequest) or AJAX with long polling (XMLHttpRequest, Script tag).

I feel like AJAX with long polling is the direction I want to head in, more specifically, the XMLHttpRequest long polling. However, I don't know anything about that. I've also read about the AJAX Push Engine (APE) and it looks cool. Is APE a possible way to do this?

Actual Question

So how would I do the above using the Comet technique?

Thanks in advance.

+4  A: 

Here's an example of a chatroom using node.js, source code here.

I believe the client uses polling, but this example is interesting because the server side is in JS too, and node.js is efficient for this type of stuff.

meder
Thanks. This seems cool. Do you know what technologies are being implemented... besides javascript?
Hristo
As far as I know it's just client-side javascript combined with the server-side javascript which is the polling server/node.js app.
meder
What is node.js?
Hristo
http://stackoverflow.com/questions/1884724/what-is-node-js
meder