Chat application AJAX polling

前端 未结 12 1615
天命终不由人
天命终不由人 2020-12-14 20:11

In the project I am currently working on, we have the need to develop a web chat application, not a very complex chat, just a way to connect two people to talk about a very

相关标签:
12条回答
  • 2020-12-14 20:58

    You might also want to look into Comet.

    It's used by GTalk, Meebo, and many other chat applications. A few years ago when I was experimenting with it, there weren't very many libraries or details about server architecture to implement it, but it looks like there is a lot more stuff out now.

    Have a look at the cometd project for more technical information.

    0 讨论(0)
  • 2020-12-14 21:02

    The trick is to realise that the only time your app needs to invoke CGI on the server is when someone says something. For the regular polls, poll a static page that your CGI script updates whenever there is new chat. Use HEAD requests, compare the timestamps with those last seen, and only do a full GET when those change. I have a simple naive chat application implemented this way, and the load and bandwidth usage is negligible for the few tens of simultaneous users we have.

    0 讨论(0)
  • 2020-12-14 21:04

    I agree with John. But there was another question that was not answered.
    I have done this but instead of using a database we used a flat file, it did eventually cripple the server, but it wasn't until we has ~450 active users, and if we had done it with a database it probably would have fared better.
    This was done on a basic hosting account from Godaddy.

    Edit: BTW Godaddy sounded less then amused when I got the phone call.

    0 讨论(0)
  • 2020-12-14 21:08

    Checkout Speeqe. Its a open-source solution for Web-based chat rooms that uses BOSH and XMPP behind the scenes.

    0 讨论(0)
  • 2020-12-14 21:11

    You might also want to look into Comet.

    I thought everyone used cometd for this sort of thing.

    BOSH is a standard for transporting XMPP over HTTP. It involves Comet for pushing data to the client.

    0 讨论(0)
  • 2020-12-14 21:12

    I think polling is the simplest approach and would recommend that first. If the load becomes a problem start, looking into more complicated techniques. A good discussion on the pros and cons are here - http://www.infoq.com/news/2007/07/pushvspull
    http://ajaxian.com/archives/a-report-on-push-versus-pull

    0 讨论(0)
提交回复
热议问题