Server-Client Messaging Notes

The W3C's Web Apps working group has recently produced a couple of candidate recommendations for APIs that allow server to client messaging, Server-Sent Events and WebSockets. This page provides an overview of both, and links to example implementations.

Server-Sent Events

(EventSource API)

Server-Sent Events (SSE) provide a one-way channel for text messages from server to client over an HTTP connection. SSE provides reliability by automatically reconnecting, after a defined backoff period, in the event of a broken connection. The protocol provides identified message types (channels).

We implemented an example that pushes mote ASN, in Ken's 'develop_SW-1' branch. On the server side, no 3rd party software is required. On the client side, we used yaffle's polyfill to provide the functionality for non-supporting browsers.

Concerns

  • Requires a multithreaded server since the connection is persistent. Bottle supports several servers, and we likely would use CherryPy.
  • Not implemented by Internet Explorer.

WebSockets

The WebSocket (RFC 6455) protocol provides full-duplex (two-way), message-based communications over a single TCP socket. Messages may be text or binary. It is designed for a web application, including initialization via an HTTP Upgrade header so the protocol may coexist on the HTTP port.  At the same time, as a messaging tool, it allows other two-way messaging protocols to run on top of it. See the Messaging and Queueing topic below. Due to its close relationship to HTTP and its flexibility, we expect it to become widely adopted. It already is supported in the latest versions of the well known browsers.

We implemented an example that pushes mote ASN, in Ken's 'develop_SW-1a' branch. On the server side, we used the ws4py websocket library, v0.3.0-beta. Required some manually applied patches as described in the class comment for openVisualizerWeb.WebSocketHandler. On the client side, we used the jQuery.WebSocket polyfill, as of the more recent commit, from 2013-03-09.

Concerns

  • Incompatibility with firewalls and proxies. We suspect these issues eventually will be ironed out, but that may take a long time.
  • Session maintenance – how to reestablish a connection if necessary?

Messaging and Queueing

Can messaging and queueing be integrated with WebSocket use? The links below show significant work being done with well known protocols and products.

  • IBM MQ and Mosquitto support MQTT over WebSockets
  • Javascript library for STOMP over WebSockets. Notice the linked page describes built-in support for this approach by HornetQ, ActiveMQ, RabbitMQ.