Enhancing Web Applications via Web Sockets

John Fallows

Next-generation Web applications will no longer need to describe interactive communication by serving lots of mini-documents over HTTP. They will instead take advantage of the HTML5 Web Sockets protocol, which is designed to deliver the performance of a bi-directional, full-duplex TCP connection, while maintaining compatibility with the HTTP constraints of the Web. Using this approach elevates the communication capabilities of a Web Socket application to rival that of traditional desktop and modern mobile applications.

The Web Sockets protocol is optimized to reduce communication overhead to a minimum. After the initial HTTP-compatible handshake, each message payload transferred via Web Sockets contains only a very small number of additional framing bytes, usually just 2 bytes. Comparing this to the approximate 1,000 'overhead' bytes in a typical HTTP request-response yields significant gains by a factor of 500. The latency characteristics of Web Sockets are also impressive.  The maximum latency of message delivery from Web tier to browser can be reduced by a factor of 3 for Web Sockets compared to the HTTP request-response communication approaches used by Comet, Reverse Ajax or Ajax Push.

Unlike the HTTP request-response paradigm, Web Sockets represent a connection-oriented architecture, which means that connections stay open between message transfers until they are explicitly closed by the client.  Clearly, leaving a connection open has the potential to create additional overhead on the server, but this occurs only when the client anticipates server-initiated communication, such as subscribing to a stock ticker feed.  The optimized Web Sockets wire protocol lends itself to highly scalable Web Socket server implementations, where the transfer of each message consumes minimal resources, allowing many thousands of connections to be handled on a single server.  Kaazing has successfully demonstrated one million connections to our Kaazing WebSocket Gateway to illustrate this point.

Enterprise-class Web application features such as high availability and disaster recovery are easier to deliver via a Web Sockets based architecture, as Web Sockets are connection-oriented; making it very clear if/when a Web Socket becomes disconnected.  This creates a straightforward approach to determine exactly when additional work might be required to recover from connection loss.  As a result, there is no need to perform repetitive tasks on the server in preparation for a potential connection failure that might never occur.  This provides a resilient architectural approach that delivers rapid recovery from network outages, while maintaining the scalability strengths of Web Sockets under normal operations.

Web Sockets is not simply a better version of Ajax, but instead is a quantum leap in browser-based communication. Web Sockets represent a fundamental shift in Web application architecture, eliminating the need for application glue code in the Web tier.  With Web Sockets, next-generation Web applications will consist entirely of highly cacheable static resources such as HTML, scripts, styles and images which are served over HTTP, while bidirectional, full-duplex communication is provided by Web Sockets. Web Sockets represents a best-of-breed approach to Web applications, replacing the existing work-around approaches that have been attempted by various plug-in technology vendors using raw sockets. The current approaches have had limited success due to problems traversing HTTP-constrained firewalls and proxies that are a fact of life for any enterprise client deployment, and are increasingly common for end-user deployments where anti-virus programs may include a transparent HTTP proxy.

Kaazing provides support for the HTML5 Web Sockets JavaScript APIs in HTML4 browsers, seamlessly falling forward onto native browser implementations as they becomes available, as illustrated by Chrome 4, which supports Web Sockets today.  We also support native Web Socket APIs in Flash, Silverlight, JavaFX, Java desktop and more, as we believe in the architectural unification across Web, desktop and mobile devices made possible by Web Sockets. No longer does the Web version of an application need to become a redesigned port of the original desktop or mobile application.  Web Sockets reduce architectural complexity because each version of the client application can communicate using the same protocol, and the majority of application development effort can be focused on delivering a compelling end-user experience, rather than on the challenges of bidirectional full-duplex Web communication.

By effectively delivering a Web-compatible TCP stack to the browser, HTML5 Web Sockets represents a massive step forward in Web communication, but this is only the beginning.  We can now extend the reach of traditional server protocols to the browser using Web Sockets. For example, extending the reach of an enterprise messaging system protocol such as XMPP, AMQP, or even a JMS vendor protocol becomes entirely straightforward.  This changes the Web application programming model from coding against HTTP document APIs that require a programmatic Web tier such as Java Servlets, to coding against first-class protocol clients that have the same capabilities as any other desktop or mobile client using the same protocol to communicate directly with the enterprise messaging system.

If we consider that traditional desktops have the full power of the Internet at their disposal because they can use any protocol they like to communicate, and also that Web browsers are limited due to the HTTP constraints of the Web, then it's an obvious conclusion that Web Sockets bring back the full power of the Internet to Web browsers and Web architects alike.

Add Comment      Leave a comment on this blog post
Jun 27, 2010 3:06 PM Oliver Mezquita Oliver Mezquita  says:
For those of you who are interested, I developed a small example of web sockets in action, using ASP.NET. Click on my name and you'll find it there! Reply
Jun 12, 2011 10:06 AM Briggs28Savannah Briggs28Savannah  says:
I opine that to receive the business loans from banks you must present a firm reason. Nevertheless, once I've got a car loan, just because I wanted to buy a bike. Reply
Feb 4, 2012 7:02 PM used parts used parts  says:
Everyone use web world, but, few understand the nitty gritty of its operation. I am extremely glad to learn about how to enhance web applications via web sockets. Everyone associated with web application would be immensely benefited by the discussion. thanks for sharing. Reply

Post a comment





(Maximum characters: 1200). You have 1200 characters left.




Subscribe to our Newsletters

Sign up now and get the best business technology insights direct to your inbox.