How do chat rooms work?
|
demo 22 Dec 2008 10:28pm So I've always been curious, and never been able to figure out, how exactly do chat rooms work? (as far as the coding behind them) I've had some ideas such as they post to a file, or a mySQL database and then you just get a page that refreshes every couple of seconds or would check a database every couple of seconds to see if there has been an update and then refresh the page with the update but that doesn't seem like the right way to do it.. So does anyone know how chat rooms actually do work? I'm not asking for specific code but more of a general idea. Thanks for any enlightenment |
Answers
|
demo 22 Dec 2008 10:37pm As far as the coding behind them....LOL if someone says they are a horny teenager that means they are really an undercover cop... HAHA sorry...i have no idea.... |
|
demo 22 Dec 2008 10:46pm Chat rooms are actually much much simpler than that. In fact, a simple chat room is often used as a assignment for students learning network programming. Your basic TCP/IP-based chat room, such as IRC, MUDs, MUSHes, MOOs, etc use "line-mode" telnet-like sessions to connect. In layman's terms, it opens a connection to a central "chat server" and leaves the connection open. Commands are entered a full line at a time and incoming text is received a full line at a time (as opposed to one character at a time). When a user enters a line of text, that text is sent to and interpreted by the chat server. The chat server, if applicable, then sends the text on to other users currently connected to that chat server. For more advanced chat systems, like IRC, the client software will take text coming in from the chat server and make it pretty for the end-user. Here's a website showing very simple chat server code in Java. You'll note its only about 100 lines of code total. http://www.acm.org/crossroads/xrds6-1/ovp61.html Now, for Web-based chat: Most web pages that do "chats" actually use Java or Flash or some other 3rd party technology to do exactly what I described above. It really is the easiest way. However, there is a technique that allows real-time chats on a browser that only requires JavaScript. This is using a "reverse-AJAX" technique known as (don't laugh) Comet. For reference, Google Talk's web-based chat uses Comet. Comet actually isn't that much different than telnet-like sessions. Specialized JavaScript and a special web server force a TCP/IP connection to stay open making the browser think that more information is coming (this is called "long polling"). Then the information is streamed back and forth along this connection just as described above. Here's a somewhat technical paper that talks about Comet and chat rooms. http://cometdaily.com/2008/10/30/comet-apps-will-not-scale-equally/ |
|
demo 22 Dec 2008 10:50pm Your logic is correct for traditional web-based chat rooms, where the data is being pulled by client (i.e.: web browser) from the server. So every certain time, the client opens a connection to the server, asks if there's any update and gets the update if there is some. In desktop chat software and in modern web-based one, what happens is the chat software / browser keeps a connection with the server open and it waits for data to come in from the server. As soon as there is some update, the server will push the data out to the client(s) and the client will act on it (e.g.: show new message in the user interface). Storing data in the database is optional with this method. |
Related
Submit Answer
You must be logged in to post an answer. Please Login or Register.
Powered by phpMyAnswers.