out of this world Comet programming and a web-based chat
Asked Answered
F

1

12

Current Project Setup

I've been working on a web-based chat, similar to Facebook chat. At the current state, 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 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 :)

Obviously this is really inefficient, but it is the only way I could get things to work. Now I'm looking for the ways to make it better, to do it correctly!

Some Research

Now, I have heard about Comet Programming and that this is the way to open a long-lived HTTP connection with the server, but I'm not familiar with the technology or the ideas behind Comet. WebSockets for HTML5 is probably even better, but since that is not in full swing nor is it supported by all browsers, I'll stick with what works.

According to Wikipedia, there are several ways to develop with the Comet style: Streaming (hidden iFrame, XMLHttpRequest) or AJAX with long polling (XMLHttpRequest, Script tag). However, I don't know anything about this. I've also read about the AJAX Push Engine (APE) and it looks cool, but I don't want to use a third-party for the time being.

I've recently stumbled upon WebChat 2.0 so I'm going to be looking through the source code to try and understand how it all works.

On to the question(s)

So where can I find example code/tutorials on how to get started with this kind of project? How would I implement the Comet technique? How do I set up the long-lived HTTP connection with the server?

Find answered 9/7, 2010 at 16:59 Comment(2)
I recommend you look at now.js It makes this stuff trivial and when used properly the abstraction isn't very expensive. It does require using node.js though but node was build for real time communication.Failing
@Raynos... thanks for the suggestion. that is definitely one possibility. however, I was hoping to use PHP to handle the server-side; with node.js, wouldn't all server-side stuff be JavaScript?Find
C
9

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.

Cholecystectomy answered 9/7, 2010 at 17:1 Comment(2)
Thanks. This seems cool. Do you know what technologies are being implemented... besides javascript?Find
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.Cholecystectomy

© 2022 - 2024 — McMap. All rights reserved.