Writing a Chat Script

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
Sponge
Forum Newbie
Posts: 3
Joined: Mon May 12, 2008 11:18 pm

Writing a Chat Script

Post by Sponge »

I'm currently working on writing a chat script that allows for clean, easy interaction between users on my site. I've got a working version, but it uses a fixed, user-entered time value for refreshing the frame. When it does refresh, the frame goes blank for a fraction of a second. This is to be expected, but it's a nuisance.

So I'm looking for two things.
1. Is there a way to make it refresh in a "cleaner" way? Put more simply, can I do something that will cause new messages to display as opposed to refreshing the entire frame?
2. Is there a way to automatically refresh the chat frame for all connected users when a new message is entered? This is a secondary priority, but I'm pretty sure I've seen something like this before.

Thanks,

Adam
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Writing a Chat Script

Post by pickle »

You're probably looking for an AJAX solution.

This pre-made chat program looks nice: https://blueimp.net/ajax/
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: Writing a Chat Script

Post by Rovas »

Or you could make a Java applet which offers more advance features chief among them using SSL for secure communication. Look one Google there are examples.
Sponge
Forum Newbie
Posts: 3
Joined: Mon May 12, 2008 11:18 pm

Re: Writing a Chat Script

Post by Sponge »

Thanks for the suggestions.

Although I may need an AJAX solution, a premade program like that isn't quire what I'm after (even though it looks really neat). I need something that I can throw into a frame at the bottom of a page with relative ease. The system I have now accomplishes that, but the refresh is problematic.

JAVA isn't quite what I'm after, either. A JAVA applet would be a bit over-the-top. I need something simple.

I'm just after a way to refresh a frame in the least obtrusive way possible. If I can refresh the frame after one of the users connected to teh database makes an input, that'd be all the better.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Writing a Chat Script

Post by pickle »

As far as I know, there's no way to "push" information to a client. So, the only option you have is to refresh the window every X seconds and every time the user submits some information. A window refresh is pretty easy - there might be a window.refresh() or window.reload() function, but window.location() would work as well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Writing a Chat Script

Post by VladSun »

pickle wrote:As far as I know, there's no way to "push" information to a client. So, the only option you have is to refresh the window every X seconds and every time the user submits some information. A window refresh is pretty easy - there might be a window.refresh() or window.reload() function, but window.location() would work as well.
As discussed before, one could make the server response to last for a very long time if there is nothing to update, and to response imidately if there is. This way it's almost realtime :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply