Sockets with JavaScript
We’ve seen a great push towards using JavaScript in modern websites, using AJAX and JSON for dynamic websites which start to feel more like applications instead of plain boring pages. One of the problems which more interactive sites face is the constant polling of the web server due to the way HTTP works. Various web apps these days tend to poll for data with the server keeping the connection alive without sending any data, once data has been sent then a new request is sent asking for more data.
One particular web app which isn’t that great is IRC web chat. Most IRC servers are keen on users connecting from their real connection, as it’s hard to track abuse when connections are being proxied by a web server. Using AJAX or JSON with a web server isn’t that ideal either, browsers have to constantly poll and refresh with the server to receive the data, this typically requires a light weight web server as Apache with PHP or Perl is hardly efficient for multiple users. The most common approaches over the years has been CGI:IRC, but this is just yet another inefficient Perl script which keeps the connection open. One of the oldest methods is using a hefty Java application, hardly friendly for users.
So, why not use sockets with JavaScript? Obviously JavaScript can’t do it directly, but with Adobe Flash and something like socketBridge (or this improved version) you could control a socket with mostly JavaScript. The only problem with Flash and sockets is that it would have to connect to a policy port before being authorised to connect to that particular port, however it would be a much lighter solution for the server compared to all the polling techniques.
I’m tempted to try and create a web IRC client using JavaScript and the Flash socket bridge. Even if other IRC networks won’t open a port for Flash policy requests, you could do something similar to the other web chat apps – use your server as a proxy.
You could use a socketBridge to flash, OR you could use an existing solution.
Check out Orbited’s TCPSocket
http://www.orbited.org (hmm weird, looks like their site is down – March 11th 10am PST)
They’ve also got the inklings of a javascript irc API so you can make calls like irc.join(’#channel’)
I just got a working version of their hello world irc chat app up and running over the weekend.
http://irc.hackyhack.net
Also check out http://www.mibbit.com if you haven’t already heard of it (but they’re closed source)
You can find me (KevBurnsJr) on irc.freenode.net
Happy hacking
March 11th, 2009 at 5:02 pmIf you’re only pulling data from the server http streaming and long polling are way more adequate than flash sockets.
Sockets only make sense if you’re pushing lots of data from the client to the server – or need the extra, unnoticeable speed difference for pulling data.
And then again – it might not even be better, it’s a flash bridge afterall …
March 13th, 2009 at 10:25 pm