Jump to content

Php Ajax Chat


razaviv
 Share

Recommended Posts

hello, i have online users system that shows who is online from specific user friends list automaticly, by someone logouts he immidately considers as offline and invisible in the specific users list.i want to build chat with these users, once the user clicks on friend from his online friend list will appear a chat with him, like facebook.so i built the chat it self and it works, i did it with ajax and the messages are insert to the database and automaticly select by settimeout of js by 450ms.first: if someone have anyway better than the way the chat it is right now, please note it.second: while the chat appears after he click on someof his friends from the online users list it automaticly reload the pages to receive datas from the different user he speak with, and if he try write in the chat box it will clean the data he writes because the chat box is in the page that reloads automaticly, and what he type every 450ms will delete to nothing. i thought about when onkeyup it will stops the settimeout and when message sent will start it again, but two problems: first i think (not sure) its impossible to stop the js function from the page the page the function work by itself. second problem: if he stops the settimeout even for a while he will cant receive any data will typing.so if please someone knows a good algorithm for such thing please help me.oh and sorry for my bad english, when you comment please dont use too complicated words.. thanks

Link to comment
Share on other sites

ill try make it clearier.you have list of friends online.you hit one friend to chat with him.immidately (no refresh) you have a window of this friend to chat.by the time you just send him message it also automaticly open the chat for him without reload.his window that opened automaticly has two options: one is textbox so he can send you data, and second is div who receive data by ajax.its hardly complicated to use the chat with the site togther so it will have no bugs and it will works great without refreshing.and bytheway can i run javascript function with php without any onClick, onMouseOver function? such as:if (php code){run with the php code the js function name}if so, how?

Link to comment
Share on other sites

I understand what you're trying to do, what I don't understand is what the problem is.You can have PHP print Javascript code, so PHP can print some Javascript code to execute a certain function, but that's not going to execute the function immediately. PHP runs first on the server, and Javascript runs later on the browser. So you can have PHP print Javascript code, but you can't execute Javascript code directly from PHP.

Link to comment
Share on other sites

okay, lets start it from nothing. you have some way to build such chat as i want to build? chat like facebook with database and ajax.please tell me how, its just impossoble hehe, i thought about just every algorithm for such thing and nothing works!

Link to comment
Share on other sites

I haven't personally built a chat client. Your chat application can be broken down into many small problems, and each problem has a solution. One problem might be figuring out who is logged in, but there's a solution for that. One problem may be figuring out when to open a new chat window when someone starts a chat, but there's a solution for that. Nothing with this is impossible, it's just a lot of small problems. If you're looking at it like one big problem then it might look impossible, but you need to break it down into the small pieces and then figure out how to solve each piece, and then how all of the pieces work together.

Link to comment
Share on other sites

yes i know, i solved alot of problems such this, you true. ill keep try and dude if you find something that can help please send me message.ill take a paper bytheway so ill can write the algorithm perfectly so clear the problems and not face with bugs from the beginning.

Link to comment
Share on other sites

  • 5 months later...

A protocol is just a specification that client and server agree to follow so that communication can be interpretted. Each chat system could have its own protocol. You could look up the IRC protocol.The listener on the server could be PHP, but it would have to be constantly running. Most servers stop the PHP script after 20 or 30 seconds. Java is probably a better server-side solution for it. Web hosts that allow programs to be constantly running on the server are usually pretty expensive. On the client, you need a Java Applet or a Flash application if you want the chat to run in the browser.

Link to comment
Share on other sites

wow that arrow chat looks impressive. I'm guessing that uses Comet. I'm curious about learning how to do this. I tried googling for some tutorials but I didn't find anything useful. Have any of you worked on anything using Comet? Know of any good resources?

Link to comment
Share on other sites

Have you tried the original article? Note you often need a special HTTP-like server to handle Comet requests, as normal HTTP connections are not supposed to be held open for very long, and servers are not supposed to handle many simultaneous such connections either.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...