How to get realtime updates?
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 d开发者_StackOverflow中文版o 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?
To do real time communication you need a proper connection.
You can use 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 techniques.
My personal recommendation is a WebSocket abstraction like socket.io.
Socket.io builds on node.js which Serverside Javascript. It excels at evented asynchronous real time communication.
If your going down the node route you might aswell pick up now
to make your life easy. It has a screencast about making a chat server in 12 lines.
Use COMET to push your messages to the client instead of polling your server all the time
See: Using comet with PHP?
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.
精彩评论