razaviv Posted March 8, 2010 Share Posted March 8, 2010 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 More sharing options...
justsomeguy Posted March 8, 2010 Share Posted March 8, 2010 Are you saying that when someone clicks another user the page reloads, and you want to stop the reload? Link to comment Share on other sites More sharing options...
razaviv Posted March 8, 2010 Author Share Posted March 8, 2010 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 More sharing options...
justsomeguy Posted March 8, 2010 Share Posted March 8, 2010 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 More sharing options...
razaviv Posted March 8, 2010 Author Share Posted March 8, 2010 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 More sharing options...
justsomeguy Posted March 8, 2010 Share Posted March 8, 2010 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 More sharing options...
razaviv Posted March 8, 2010 Author Share Posted March 8, 2010 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 More sharing options...
skaterdav85 Posted August 20, 2010 Share Posted August 20, 2010 are chats usually built by storing messages in the db and having JS run a timed function that retrieves the latest messages through AJAX? Or are they built using another protocol? Link to comment Share on other sites More sharing options...
Ingolme Posted August 20, 2010 Share Posted August 20, 2010 Chats aren't usually made using HTTP protocol. They open a persistent connection and have listeners on the client and server. That's a real-time connection. Link to comment Share on other sites More sharing options...
skaterdav85 Posted August 20, 2010 Share Posted August 20, 2010 what protocol is used? Would the listener on the client be in JS? Could the listener on the server be in php? Link to comment Share on other sites More sharing options...
Ingolme Posted August 21, 2010 Share Posted August 21, 2010 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 More sharing options...
skaterdav85 Posted August 22, 2010 Share Posted August 22, 2010 I don't think gmail, facebook, and myspace use a Java applet or flash for their chat systems. What do you think those applications are using? Link to comment Share on other sites More sharing options...
Synook Posted August 22, 2010 Share Posted August 22, 2010 There is always Comet - that is what Facebook Chat, at least, uses. Link to comment Share on other sites More sharing options...
HungryMind Posted August 22, 2010 Share Posted August 22, 2010 HI!Try These Links:ArrowChatGMail / Facebook Style JQuery Chat Link to comment Share on other sites More sharing options...
skaterdav85 Posted August 26, 2010 Share Posted August 26, 2010 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 More sharing options...
Synook Posted August 27, 2010 Share Posted August 27, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.