IM/Chat over HTTP without browser plug-ins

The past couple of months I’ve been pondering an idea. It isn’t a new one, or anywhere close to groundbreaking, but I don’t think anyone has accomplished anything quite like it before. I want to write an IM/chat system that is as responsive and real-time as native IM/chat programs, and that operates solely over HTTP, with vanilla browsers – no Java applets, no ActiveX plug-ins, just Javascript that all modern browsers support. The advantage of such a system is that it could traverse firewalls and proxies traditionally used to block users from using IM/chat, and that users would never be prompted to install applets or plug-ins that many users distrust (for good reason too).

So, why hasn’t it been done before? When I first had the idea I thought surely there would be at least 10 similar projects already. I found several attempts, but none seemed to fit the bill – some communicated entirely over HTTP but required Java applets, some didn’t use any applets or plug-ins on the client but weren’t responsive or real-time (updates were polled for ever 2 secs or so). Looking at the current field of attempts there seemed to be a couple of challenges that I would have to find a way around.

  • HTTP/1.1 supports keep-alive connections, but they don’t work well for 2-way communication. The client still must initiate every exchange, so the server can’t send messages to the client on demand.
  • A client repeatedly polling a server for messages (even when there are none for it) puts a lot of unnecessary load on the server, and generally results in a poor user experience. The programs I looked at that used this model often felt very laggy and sluggish – they certainly didn’t feel like native applications.


So, what’s the solution? I don’t know for sure, but I think I’ve got a start. Basically the client uses XMLHttpRequest calls to open up a connection to the server in the background (so no page reloads are required). The server accepts the connection and just sleeps until it has a message to send the client. By setting the script timeout to be very long or infinite on the server the connection never times out, even if the client has to wait hours for a message because nobody wants to talk to the user (as long as the network between client and server stays healthy, but that is assumed). Once the server does have a message to send back to the client (such as a message from another user, or notification that a buddy has signed on) it simply sends it back on the connection the client initiated. Now, once the client has received the message and processed it accordingly it immediately calls XMLHttpRequest again to start another request to the server, and so it starts just waiting for the server’s next message to it.

Not quite ideal as far as IM/chat protocols go, but it fits within the confines of HTTP, has less overhead than a system where the clients are constantly polling the server (instead of basically sleeping until responded to), and allows for a responsive native feeling application (because all connections and updates can be done without reloading the page). My proof of concept experiment seems to have been a success (at least for Mozilla browsers). It seems to mostly work in IE as well, just IE doesn’t handle pre tags like I expected it should. When I get time I’ll be working on developing the idea. Hopefully soon you will see a more comprehensive example of my idea here.

11 Responses to “IM/Chat over HTTP without browser plug-ins”

  1. Tom Says:

    http://www.socket7.net/lace/ and http://cgiirc.sourceforge.net/

  2. Ray Says:

    Good links Tom. Neither of those fit what I was envisioning exactly, but they will give me some good starting off points. Wonder why I didn’t find them before…

  3. this is maddy cashner Says:

    heyyy…. i was lookin at ur picss of u guys and ian…awwww hess adorable…hes gonna be a modell…i miss u guys….ur house is big and beatifull….i hope u guys are doign good…and just to let u know we miss u down here…and were all thinkin bout u guys…i heard jess had fun in texas wiht u guys…

    my dad has an e-mail…whateverittakes@sbc.global.net

  4. Treehouse Cityguide Maintainer Says:

    I’ve written a chat based on lace, and have been looking for a way to reduce the bandwidth taken up by polling. Have you developed this idea any further?

    I suppose that your idea would ideally also involve a dedicated chat server on the server itself…

  5. Still Not Perfect » Jabber + Punjab + JWChat = almost what I’m looking for Says:

    [...] A couple people commented on my project idea for instant messaging over HTTP. After looking at the open source IM market in more depth I’ve found that the pieces I was looking for are actually all there, mostly. [...]

  6. Justin Baeder Says:

    It’s been done recently with Ajax: http://www.unwieldy.net/ajaxim/

  7. Spiros Says:

    Have you ever heard of a project called “Pushlets”? It provides a pure HTTP information push mechanism (no plug-ins, no polling, real-time synchronous communication based on DHTML and javascript). The project’s site is “http://www.pushlets.com/“. Also there is a commercial product “LightStreamer” based on the same philosophy (http://www.lightstreamer.com/).

  8. Niklas Says:

    Is http://meebo.com something like what you desire?

  9. greensmile Says:

    Ray: a whole lot a quiet on this channel for a guy who has so much on the ball. Did you finally put together exactly the kind of chat client and server[lite] you wanted?
    Not idle curiosity here. I just got this IM/HTTP notion myself…for similar reasons too. I was about to do the sever end in Perl CGI, figuring the asynchronous tricks could be carried by XMLHTTP…I had miles to go just to spec it out to a workable level of detail. You can see how much trouble you and your commentors have saved me.

  10. Ciarra Says:

    Hey Dad its Ciarra I finally found out where I can Chat with you at

  11. kevin Says:

    Facebook does this already

Leave a Reply