chat room theory and development

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gth759k
Forum Commoner
Posts: 76
Joined: Mon Jun 15, 2009 3:04 am

chat room theory and development

Post by gth759k »

I recently built a chat application with php/mysql/ajax, but I'm hoping I can find some advice on how to make it better. The user types their comment and presses submit; I used ajax to add the value of the comment box to my database with an onclick function. Meanwhile, a body onload ajax function updates (every 500 ms) the div where the conversation is taking place. My ajax works fine; the php scripts all do what I want them to do. Essentially, the conversation div updates often enough to where when the user presses submit, their comment appears to wind up in the conversation div instantly, but it really only gets put in the database. So, I tested it out online with a friend and there were some time delay issues. My friend said sometimes their comment didn't go through and the javascript timing seemed erratic, i.e. as if 500 ms wasn't the same every time. We were using different browsers on purpose to test cross browser compatibility, so that may be part of it and I'm sure internet connection speed is a factor. Since I have some experience with flex apps, I thought I'd try and build a flash chat room. However, I'm not even sure my whole theory on how chat rooms work is sound. Does anyone have any experience or knowledge in this area? For instance, I've read about networked game programming with java, where the "state" of the game is updated in all instances of the program; I can see how this might be used in a chat application. Anyways, I apologize for the length of this post. Lol. Thanks in advance!
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: chat room theory and development

Post by daedalus__ »

winded... there are java based chat applications that work using irc. maybe you could find some inspiration there.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: chat room theory and development

Post by VladSun »

Take a look at:
http://en.wikipedia.org/wiki/Comet_(programming)

I would advice you to use a "long polling" approach.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: chat room theory and development

Post by VladSun »

Or you could try my Java-2-JavaScript streamer :)
viewtopic.php?f=14&t=106873
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply