Excited about Web Sockets
Real Time Web
Wednesday, 28 July 2010 10:45

I'm excited about web sockets and you should be too. The idea behind web sockets is to allow a client to maintain a connection with a server, the main benefit of which is allowing the server to send data to the client instead of the client having to poll the server for data. The result is real time event driven client/server communications with low overhead.

Long polling has long been the best option to accomplish this behavior. Check out chat.nodejs.org for an example of a chat application that uses long polling. What I'd like to point out here is that it was already possible for a server to send data to the client on-demand. So, what makes web sockets so fantastic? It seems to me that the main game change here is scalability. Long polling is essentially a hack to emulate a persistent socket connection. There's a lot more overhead involved in long polling. Web Sockets allows this to be done the natural way -- by actually keeping a socket open.

But wait! Web Sockets are only supported by a few browsers! That's right. You really can't make a website utilizing Web Sockets just yet because it's only supported by the latest versions of a few browsers. That's where web socket wrapper libraries come in handy. These libraries attempt to use Web Sockets and if they're not available, they are emulated using other methods such as Flash sockets or even long polling if necessary. I've been looking into a few of these lately and I will write about what I learn.

So far I have been focused on web sockets for Node.js because that is my latest pet technology. There appears to be two leading options. The first is Socket.IO and the second is node-websocket-server. From what I have been told and what I have experienced, Socket.IO is more simple and easy to use compared to node-websocket-server which is a bit more complicated, but also more scalable for your effort. They both appear to be very young which makes me a bit nervous. There are libraries like Kaazing which are much more complete and proven. This is expected since Node.js is very young itself.

This is all very fun and I'll post more as I learn more.


blog comments powered by Disqus