Note in Programming page
Created Mar 11 10, Updated Apr 28 10 18:44
A richer web with HTML5 Web Sockets? go to comments

HTML5 Web Sockets represent the next evolution of web communications: a full-duplex, bidirectional communications channel that operates through a single connection (TCP socket) over the Web; meaning reduction in unnecessary network traffic and latency, cleaner network code, more interactive and responsive web applications. It is not just an incremental enhancement to conventional asynchronous HTTP communications (e.g. AJAX and Comet ); it represents an enormous advance for interactive and real-time (event-driven) web applications.

WebSockets enables establishing a bidirectional communication channel. The WebSocket protocol is not build on top of HTTP, it defines the HTTP handshake behaviour to switch an existing HTTP connection to a lower level WebSocket connection. WebSockets does not try to emulate a server push channel over HTTP. It’s a ~ low level framing protocol on top of TCP.

Example (javascript, server side):
n.b. the WebSocket protocol supports a diverse set of clients (e.g. JavaScript, Adobe Flex, JavaFX, Microsoft Silverlight, etc…)

Establishing a connection:
var myWebSocket = new WebSocket("ws://www.websocket.org");
n.b. to establish a WebSocket connection, the client and server upgrade from the HTTP protocol to the WebSocket protocol during their initial (HTTP) handshake.
n.b. the connection itself is exposed via the onmessage and postMessage methods defined by the Web Socket interface.
Then associate a series of event listeners to handle each phase of the connection life cycle:
myWebSocket.onopen = function(evt) { alert("Connection open ..."); };
myWebSocket.onmessage = function(evt) { alert( "Received Message:  "  +  evt.data); };
myWebSocket.onclose = function(evt) { alert("Connection closed."); };
To send a message to the server, call postMessage (with the content you wish to deliver). Call disconnect to terminate the connection…
myWebSocket.postMessage("Hello Web Socket! Goodbye Ajax and Comet!");
myWebSocket.disconnect();

Both text and binary WebSocket data frames can be sent full-duplex, in either direction at the same time!

The Web Sockets API is being standardized by the W3C and the Web Socket protocol is being standardized by the IETF.

HTML5 Web Sockets can provide a 500:1 or – depending on the size of the HTTP headers – even a 1000:1 reduction in unnecessary HTTP header traffic and 3:1 reduction in latency. That is not just an incremental improvement; that is a revolutionary jump – a quantum leap.

Web Sockets browser / server support:
Chromium
soon in Firefox (available in the trunk of the Firefox code base)
WebKit
node.js a server side JavaScript implementation!
web-socket-ruby server/client implementation in Ruby
...

links:
The Future of the Web: HTML5 Web Sockets
HTML5 Web Sockets: A Quantum Leap in Scalability for the Web
What is an HTML 5 WebSocket [kaazing.org] (Kaazing Gateway provides an emulation layer for browsers as far back as IE 5.5)

HTML5 Server-Push Technologies, Part 2


Add a comment:

(required)

(will not be published) (required)

(optional)