HTML5 and WebSockets

The next revision of HTML (HTML5) goes far beyond updating text styles and markup. It adds support for media playback, adds a new Canvas object for 2-D drawing, and even supports real-time video compositing by using Javascript to generate image frames from real-time data streams.  HTML5 will help make the web even more interactive and alive than it is now with “Web 2.0” apps.

html5-logo_2

I think one of the most interesting additions is the API for WebSockets. The WebSockets API will let Javascript on a web-page open TCP connections to web-services to send and receive data through internet pipes. A WebSocket enabled Javascript program can also modify DOM elements on the page and draw on a Canvas. With these capabilities, the web-page will become more of a full-fledged interactive application with full-duplex communication to one or more hosts.

AJAX technologies already make web pages feel more interactive, but these pages have restricted capabilities: they can only request information from servers and do not asynchronously receive updates from a data source. “Comet” (cleaning product joke intended) is the name given to a new breed of application that implements asynchronous behavior using existing technologies in an ad-hoc manner. The term “Comet” encompasses a variety of techniques that WebSockets will help simplify.

Right now, a developer can implement something like WebSockets using Java or Flash, but both of these have the drawback that they require the user to install a runtime. Some people have been able to implement something like “server-push” using a technique called “forever frames” in which raw Javascript is piped to a browser. In other applications, server-polling suffices to give the illusion of live data.  None of these techniques satisfy the goals of being truly portable and robust with zero-install overhead.

The idea with HTML5 WebSockets is to unify all of these approaches and put the functionality in Javascript. If successful, this new capability will enable real-time live apps that live in the browser. It may even transform web pages from clients into servers. Imagine starting a home-automation server by opening a web page: that’s not the way we think of the browser right now.

Leave a Reply

Your email address will not be published. Required fields are marked *