AJAX instant Messenger

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Omego2K
Forum Newbie
Posts: 4
Joined: Mon Jun 09, 2008 5:32 pm

AJAX instant Messenger

Post by Omego2K »

I am looking for a technique to implement an AJAX instant messenger. I understand that polling makes it possible, but if you look at say gmail and facebook instant messengers they seem to be, well, instant. I have tested it with two computers and I see no noticeable delay. I'm guessing that is considered a comet implementation, but I can't seem to see how it can be done. At least with php. I have tried it with ASP.NET and was able to do it with threading, however you can't thread with php. So am I missing something obvious? How is this being done? Especially since facebook uses php.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: AJAX instant Messenger

Post by VladSun »

You could keep the HTTP connection opened and wait something to "happen" (by using sleep() in a loop). If nothing "happens" then close the connection just before the timeout.
There are 10 types of people in this world, those who understand binary and those who don't
Omego2K
Forum Newbie
Posts: 4
Joined: Mon Jun 09, 2008 5:32 pm

Re: AJAX instant Messenger

Post by Omego2K »

wouldn't spinning like that be a huge a resource hog? sleep() pauses the thread itself I'm guessing?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: AJAX instant Messenger

Post by VladSun »

Omego2K wrote:wouldn't spinning like that be a huge a resource hog? sleep() pauses the thread itself I'm guessing?
While it's CPU friendly, it's not so Apache friendly (there is a limit of the maximum number of Apache spawned child processes) :)

So, if you are going to serve many and many clients don't use it, use AJAX instead.
But if you are going to use it for just a few clients (i.e. Intranet WWW application) it's better to use this approach.
There are 10 types of people in this world, those who understand binary and those who don't
Omego2K
Forum Newbie
Posts: 4
Joined: Mon Jun 09, 2008 5:32 pm

Re: AJAX instant Messenger

Post by Omego2K »

so what's the best server to use to accomplish this, on windows specifically? IIS?
Post Reply