开发者

Web based text chat?

I'd like to develop a near real time web based chat system. Any suggestions on how to implement this via jQuery, any gotchas to look out for, 开发者_Python百科and what is this Comet thing I keep reading about?

Ideally, I'd like to support up to about 5,000 concurrent chatters.


Comet, also known as Ajax Push, is often refered as "Reverse AJAX". Instead of pulling the information from the server in regular intervals, the data is pushed from the server to the browser when it is needed. That requires an open connection, for which there are several implementations.

I recommend that you use APE. Here is a demo: http://www.ape-project.org/demos/1/ape-real-time-chat.html

  • Advantage: It will be very responsive and real-time.
  • Disadvantage: You need to setup the APE server on your webserver machine.


Comet is a "push" tecnology, created to avoiding the client (javascript code) to continously poll the server. This could cause bandwith problem, because you have to create (maybe) a new TCP connection, then contact the http server, he runs some server-side logic and then sends a response to the client. With comet, if the server decide that you should recive some information (e.g., new chat message) he directly send it to the client.

There are several different implementation, you can have a start here.

the simplest implementation tecnique is the hidden iframe, but I'd raccomend the long polling wich is much more controllable.

One more thing, thake a look at HTML5 websokets, wich could be an interesting solution to your problem (not very compatible with current browser, anyway)


Check out Node.js and nowjs for node.js. Node.js helps you build very efficient servers using server side JavaScript and nowjs is a library that allows you to build real time web apps. There is even a example screen cast that puts together a basic chat application in 12 lines of code.

You could also checkout Socket.io which is another node library thats helps you build real time apps by abstracting away different transport mechanisms and giving you a unified interface to code against (supports WebSockets, Flash Sockets, AJAX long polling, JSONP Polling and Forever IFrames).

I realize you tagged your question PHP but if you are seriously considering writing a scalable system with the least amount of effort (relatively speaking) then learning Node.js is worth your time (and the learning curve is not thats steep since you probably already know JS).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜