Editorials

Web Sockets

I have recently been reminded of one of the powerful enhancements in the HTML5 specifications; web events. While this is not a technology needed for every web site, it is more than simply a tool for writing an instant messaging application. What brought this technology to mind? A web client that monitors a queue.

This is actually a fairly common scenario; especially in message based architectures. An application submits work to be performed to a queue. A queue manager picks up work off of the queue, and performs the required task. Now you have a queue in place, and want to know what the current contents, or a snapshot in time, look like. You simply want to know what jobs are in the queue.

You have two options. 1) Poll the queue periodically to get a snapshot in time. 2) Subscribe for notification of queue modification events. The second option is clearly a preferred choice. Prior to HTML 5, there was a lot of work required to wire up an event driven system, and it took even more work to enable it in a browser. AJAX made things somewhat easier, but you would still have to do some low level work with sockets or something of that nature.

HTML5 created a specification for web sockets so that you wouldn’t have to do the low level communication aspects yourself. Sockets could now be opened in a modern browser over an HTML connection instead of writing your own conversion to TCP.

What do you do if your browser doesn’t support HTML5? Or maybe you simply want to have some of the Web Socket infrastructure done for you. That’s where SignalR in the Dot Net world can simplify your world. SignalR has built a wrapper around Web Sockets making them easier to implement. Moreover, they have simulated web sockets using other older, less efficient technologies, so that you can use the Web Socket type behavior on older browsers.

What does this mean for you? You can now create a web application with something like a grid showing all the current jobs in a queue. Whenever a job is added or deleted on the server, it sends a notification to all subscribers that a change has occurred, along with the change. Now your application simply responds to the notification and updates its grid. No Polling is required. Your web server has a reduced load because clients no longer poll for updates.

Share your experience with Web Sockets. Why not leave a comment or send an Email to btaylor@sswug.org.

Cheers,

Ben