In the traditional HTTP model, documents are requested synchronously from a server and the connection is closed after the document is delivered as in the diagram below:
With Reverse Ajax and Comet, a permanent full duplex connection is established over HTTP, allowing the server to push events in real-time to the client:
This is the reverse of the standard HTTP model as now the server can push updates to the client rather than the client requesting them.
StreamHub uses a standards-based publish/subscribe mechanism to push updates in JSON or custom formats to clients. Clients can be written in .NET, Java, GWT, or Ajax. Receiving updates is as simple as connecting to the push server and subscribing to topics or channels. For example, the following Ajax snippet shows how to achieve this:
var hub = new StreamHub();
hub.connect("http://localhost:7979/streamhub/");
hub.subscribe("/channel", function (sTopic, oJsonUpdate) {
alert("Received an update on topic " + sTopic);
alert("Contents: " + oJsonUpdate['field1']); });
Publishing updates back to the push server is just as simple:
var hub = new StreamHub();
hub.connect("http://localhost:7979/streamhub/");
hub.publish("/channel", "{'field1':'value1','field2':'value2'}");
|