moose-en-a-gant Posted January 14, 2015 Share Posted January 14, 2015 I'm working on a chat using basic textarea input, post, but the problem that I'm facing is, if a person doesn't send something, then the output is not updated eg. other messages from other users updating in real time. How is that achieved when you see new database entries pop up live, milliseconds after they are entered? Do I set a constant refresh rate of some sort? How do you update a section of a webpage without "refreshing" the entire page like the POST method? Quote Link to comment Share on other sites More sharing options...
requinix Posted January 14, 2015 Share Posted January 14, 2015 A "refresh rate" sucks, but is easy to implement. If the chat is slow, like a message every few seconds, then that might work for you. You actually do it with Javascript/AJAX so there's no literal refreshing. More modern is WebSockets: you establish a dedicated, persistent connection between you and the client's browser and the two of you can trade information however you see fit. Couple downsides though. A persistent connection ties up resources on your end and can cause problems, especially on a "limited" or otherwise shared hosting server. It's also a bit harder to implement since it's not built into most web servers and PHP. Before WebSockets was Flash and Java, which do basically the same thing (but only for the client half). Quote Link to comment Share on other sites More sharing options...
moose-en-a-gant Posted January 14, 2015 Author Share Posted January 14, 2015 (edited) Hmm... that sucks I'll have to look into each scenario I have a VPS at the moment but ideally I would have a dedicated server You actually do it with Javascript/AJAX so there's no literal refreshing. Was that following the sentence prior or are you saying this is the normal solution? I think the key thing for me to figure out is how to update components of a webpage without refreshing the page... I think this sounds like javascript eg. getElementId I thought about a "if one user hits post, refresh all of the connected-user's webpages" hahaha sounds bad Edited January 14, 2015 by moose-en-a-gant Quote Link to comment Share on other sites More sharing options...
requinix Posted January 14, 2015 Share Posted January 14, 2015 (edited) Was that following the sentence prior or are you saying this is the normal solution?I wouldn't call it the "normal solution" but it is cheap and easy to do. A good start. I think the key thing for me to figure out is how to update components of a webpage without refreshing the page... I think this sounds like javascript eg. getElementIdYup. You'll find all this a lot easier to do with a Javascript library like jQuery. I thought about a "if one user hits post, refresh all of the connected-user's webpages" hahaha sounds badActually it's quite a reasonable idea, but it comes with a problem: how do you tell the connected users that they need to refresh? And if you can tell them to refresh, why not just tell them about the new post instead? Edited January 14, 2015 by requinix Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.