Question: I was chatting frequently in Facebook and as I love to code more and more so I tried to create a Chat Script! Here it is :::
<http://wooflux.co.cc/ChatSystem.1.1/ChatSystem.1.1/> 

You try it out. But it is just a beta version so there are some bugs in it. And one of the biggest bug is that it requires a good internet speed to get real time updates. But when I push my net's speed to it's maximum and then chat with one of my friends in Facebook, it work in real time! I was wondering how did they do that? Can anyone explain me how they achieved this. Currently I'm sending Ajax requests in number intervals to get real time update. So please help me out by explaining or giving a link that how did Facebook achieved real time Chats without using much of the Internet speed?

Answer: 
To do real time communication you need a proper connection.

You can use [WebSockets](http://dev.w3.org/html5/websockets/) to give you a real Browser - Server TCP connection.

The alternative to WebSockets would be a flash bridge (which uses websockets in flash) or [COMET](http://en.wikipedia.org/wiki/Comet_%28programming%29) techniques.

My personal recommendation is a WebSocket abstraction like [socket.io](http://socket.io/).

Socket.io builds on [node.js](http://nodejs.org/) which Serverside Javascript. It excels at evented asynchronous real time communication. 

If your going down the node route you might aswell pick up [`now`](http://nowjs.com/) to make your life easy. It has a screencast about making a chat server in 12 lines.
I don't know how Facebook does it, but we use `Node.js` for pushing. Visit <http://www.no-margin-for-errors.com/blog/2010/07/26/deliver-real-time-information-to-your-users-using-node-js/> for an example.