Jump to content

Creating a chat system


migroo

Recommended Posts

I am looking into creating a chat system for a website. I am not sure about the best way to do this so here is what I am thinking of doing.I would set up a data table to handle all of the chat. Who sent the message, the message its self, when it was sent etc.Then on my webpage I would have a script run that updated a div box AKA "your chat box" ten times per second or so using an AJAX request.If you sent a new message it would also update the chat box.I think this would work but I don't know if it is a good idea?Is this a good idea or is this a classic error?I have tried several of those sites that offer free flash chat boxes and I hate them because they don't look like I want them to.

Link to comment
Share on other sites

That's the general idea, however ten times a second is way too fast, you'll be crashing the browser and overwhelming your server. Every two seconds or so would be more reasonable.If you want to get fancy you could try implementing Comet.

Link to comment
Share on other sites

Is this a good idea or is this a classic error?
Actually, I'm pretty sure all non-flash and non-java chatboxes work this way. Not sure how else to do it. I've made chatboxes before, what you need is.1. Database to store your chat messages.2. PHP Page that displays messages in order of last posted (accessed by ajax of course).3. PHP Page that enters messages into the database.4. Any page a user accesses that uses ajax to do step 2 and 3.You've got the general idea and seem capable to write and implement it. Go for it.
Link to comment
Share on other sites

Actually, I'm pretty sure all non-flash and non-java chatboxes work this way.
As I mentioned, there are push techniques such as Comet available (Facebook Chat uses Comet), which allow you to update the chat window as soon as a message is posted. However, these techniques are hard to implement - polling is much more convenient.
Link to comment
Share on other sites

Okay thanks that was what I was wanting to know. I wasn't sure what sort of thing would over whelm the server and/or browser. So every 2 seconds will seem fairly close to instant?Thanks!

Link to comment
Share on other sites

Well, not exactly, but the users won't know better, unless they are communicating with each other through another means going "ooh, did you get my message?" You can always update the poster's window as soon as they send the message, so it is instant for them.

Link to comment
Share on other sites

Okay I was going to have it update instantly for the sender like you said and I think you are right they won't know that it updates ever 2 seconds and if they do its close enough to instant. I have heard of polling before and heard it is a nightmare. So doing this with 30 - 40 people will not cause any problems such over loading the server or sum such thing.

Link to comment
Share on other sites

What you are doing is polling - constantly and regularly checking, or polling, for changes. It depends on how powerful your server is, and how much bandwidth you have, but it shouldn't be too much of a problem.

Link to comment
Share on other sites

I get my hosting thought host gator and as far as I know they have excellent servers and large amounts of band width.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...