Monday, October 6th, 2008
Category: Comet
, JavaScript
, Library

Michael Carter et al have been working on js.io, a client library that gives you networking, including Comet like support, via JavaScript.
The low level work can sit upon Comet APIs, and in the future, Web Sockets, and you get high level APIs to protocols such as:
- amqp
- imap
- irc
- ldap
- smtp
- ssh
- stomp
- telnet
- xmpp
There are some demos such as LiveHelp that uses Orbited as the backend.
Thursday, September 18th, 2008
Category: Announcements
, Comet
, Framework
ZK 3.5, the latest version of the server-side Ajax framework, is out with a raft of new features. Three of those features really stand out for me:
- Comet server push
- Customization of look and feel
- Performance monitoring
Server push via polling has been available in ZK for a while, and Comet in the ZK “Enterprise Edition,” but now it is available to everyone. And it is pretty easy to use: “The implementation of server push is transparent to developers. ZK chooses which implementation to use according to the edition of ZK automatically, but it is configurable.”
Customization of look and feel has gotten much easier. ZK has followed the example of a number of other frameworks in styling its widgets with predictably named CSS styles. Changing the look and feel of an application is now as easy as changing the ZK widget style sheet. Styles can further be overridden on a widget instance-by-instance basis.
Performance monitoring is perhaps the most exciting new feature. Client-side tools such as YSlow can guide optimization efforts and give you point in time performance snapshots. But critical applications need to be monitored and tracked end to end over their lifespan. With ZK 3.5, you now have the plumbing to instrument your application to capture five data points for each request:
- T1, the time browser sends a request to server
- T2, the time server receives a request
- T3, the time server sends a request to browser
- T4, the time browser receives a request from server
- T5, the time the browser finishes processing a request
ZKStudio 0.8.2
There’s also a new version of ZKStudio for Eclipse out. The major change is that it now supports auto update via http://studioupdate.zkoss.org/studio/update
Tuesday, September 16th, 2008
Category: Comet
, DWR
Joe Walker of DWR fame on Comet at @media Ajax.
Motivation for Comet
Interested in what our friends are up to, even if no-one else cares (as twitter illustrates). And also interested in what systems/things are doing, not just people. Chat (meebo), collaborative editing (google docs), streaming financial data (lightstreamer), async updates (yes.com), online gaming, async server processing (polar rose, i.e. shift processing complexity to the server - note this could be seen as an alternative to Gears-style local processing in some situations).
The web was designed to be connectionless - Comet blatently aims to make it connected.
Performance
Actually does scale. Joe shows the following graph:

Technical
Seven ways (!) to implement Comet.
Long polling - “slow” XHR request. Server doesn’t answer immediately. Special part of HTTP to do this - chunked mode. However, IE “lies to you” - keeps saying it’s got something, but you can’t actually inspect it.
Forever frame - Send text/plain and 4k whitespace to flush IE’s buffer. Flush with script tag for each data block. Must keep restarting to avoid memory leak.
Script tags - Dynamic script blocks, can point to any domain.
WebSockets - HTML 5 standard. Cleaner solution.
ActiveXObject(”htmlfile”) - htmlfile is an activeX control similar to XHR. Normally causes “clicking” noise in browser, but there’s a hack to turn it off in most cases. Obviously, this only works in IE. Most bizzare thing is you get 49 Javascript before garbage collection, leading to hair-pulling moments when you try to work out why your 50th command isn’t executing!
Mime messaging - “What push was built on 11 years ago” - x-multipart-replace. Works really well, though with memory leakage issues, but not in IE and historically not in the other browsers either.
Flash remoting
Forever GIF (bonus technique) - keep sending out new slices of an animated GIF!
Technical Issues
Co-ordination when browser has multiple tabs open to the same server - using window.name or cookies, but better solution is multi-home DNS - each call points to the server using a different name (1.example.com, 2.example.com etc all pointing to the same IP address).
Issues detecting when browser or connection has broken.
Proxies which don’t let the stream go through in real-time - hold on to the chunks for a while before releasing them all at once. Can detect if this is happening from the browser using a timestamp technique.
… so just like with Ajax, we have to come up with hacks, likewise with Comet. Facebook and GMail show it’s possible to work around these problems and get Comet working at scale.
API Styles
e.g. with WebSocket you’re simply posting and receiving data. Event handlers for onOpen, onRead etc. Joe says this will be too low-level in many cases, hence the following styles.
PubSub - e.g. cometd. Low coupling (server-browser separation - Joe describes demo where servers hot-swapped without affecting client), inter-language interop. Good analogy to SOAP, which has gradually shifted from RPC to document exchange.
API - this looks to me like Ruby’s remote JS - server controls what’s happening on the browser. e.g. Effect.shake(”price”) on the server will make the price div shake on the client.
Data Syc API - Keep changing/updating data store. Simplest to understand.
Tuesday, July 8th, 2008
Category: Comet
JAVASCRIPT:
-
-
var conn = new WebSocket("ws://www.example.com/livedemo");
-
-
conn.onopen = function(evt) { alert("Conn opened"); }
-
conn.onread = function(evt) { alert("Read: " + evt.data); }
-
conn.onclose = function(evt) { alert("Conn closed"); }
-
-
conn.send("Hello World")
-
What if that code was part of an HTML standard? Would that make you feel better about Comet-style applications? Well, Michael Carter has pointed us to the HTML 5 discussions that give us WebSocket:
The HTML5 specification now offers WebSocket, a full-duplex communications channel that operates over a single socket. I have been listening closely, and in some cases contributing, to the process of ensuring that WebSocket will:
- Seamlessly traverse firewalls and routers
- Allow duly authorized cross-domain communication
- Integrate well with cookie-based authentication
- Integrate with existing HTTP load balancers
- Be compatible with binary data
He goes on to discuss how WebSocket is not the same as a TCP socket itself, and what that means as we develop real-time applications.
Tuesday, July 1st, 2008
Category: Comet
Michael Carter of Orbited has written about how he now likes to call Comet sockets in the browser, and has an implementation available that looks like this:
JAVASCRIPT:
-
-
var conn = new TCPSocket(hostname, port)
-
-
conn.onopen = function() { alert('connection opened!') }
-
conn.onread = function(data) { alert('RECEIVE: ' + data) }
-
conn.onclose = function(data) { alert('connection closed!') }
-
-
conn.send('Hello World');
-
The above code code is all you need to know. It will open a TCP connection to hostname:port, and will send the data “Hello Worldâ€. Any data the server sends back will be alerted with the onread handler.
The exact mechanism behind this innovation is pretty straightforward: Orbited is a router and firewall for incoming TCPSocket connections from the browser. It uses Comet techniques to establish bi-directional communication with the browser, then forwards all data over a raw TCP socket to the end point. Configuration allows access control enforcement so that the TCPSocket can only be connected to pre-approved end-points, so that the Orbited server isn’t an open relay.
While this presents a paradigm shift in the way developers are tackling real-time, web-based applications today, it’s actually a return to the original method of writing network applications. Instead of writing applications based on web frameworks and throwing a Comet server in the mix, you can simply use the client-server architecture where the browser is the client, and the server is an arbitrary TCP server.
Monday, May 12th, 2008
Category: Comet
, Games

Piotr Dachtera took his 64pola.pl, and created a scalable version using Comet. Dylan reports it as "a Jetty-powered Comet app that uses dojox.cometd on the client-side. It’s a solid implementation that shows chess moves in real-time, and to date is the best all-around Comet game I’ve seen that is live to the world."
Mathieu Nouzareth then commented that Cafe.com, a Flash based gaming platform also uses Jetty and Comet techniques (compared to AMF etc).
Friday, March 28th, 2008
Category: Comet
There has beern a lot of great Comet content recently, especially from Comet Daily of course :)
First, they gazed at their own Comets talking about maturity, together with a maturity grid. Since the project leads and vendors are grading themselves, you have to do due diligence :)
Joe Walker has written up 3 styles of API that are relevant when considering Comet services, which are:
- Traditional API Style. This API is the most obvious. If you want to set the text of a button, you call
field.setValue(43.5) or something similar. It’s possible to imagine complex APIs like the SWT library made available remotely. This type of API does not need Comet, unless the trigger for wanting to alter the UI is asynchronous.
- Message Passing Style. This API style is very simple—typically just a
subscribe() method to declare an interest in some topic, and a publish() method to declare some information to a topic. Some messaging APIs (notably JMS) add a large number of classes around this simple concept, however at its core, it’s as easy as those 2 methods.
- Synchronized Data Style. This style involves some data cache on the server that is synchronized with a similar data cache on the client (or clients).
Joe then walks through the pros and cons, and includes information on how DWR does its thing.
Colliding Comets: Battle of the Bayeux
The entire crew has a series of back and forth opinion pieces on the Bayeux protocol:
Martin Tyler of Liberator has a nice piece talking about benchmarking Comet servers which concludes:
Benchmarking Comet servers is not easy. There are lots of variables which impact the results, often in an unexpected way, so the only way to be sure is devise and run the appropriate tests. Making assumptions while testing is not good; if you need to know something it should be measured and recorded.
It is possible to achieve high numbers of users with high update rates and relatively low latency. However, a project needs to understand the implications, such as bandwidth, which are inherent in the requirements rather than the technology. A serious project should also perform benchmark tests themselves, with test scenarios similar to expected usage, rather than just looking at some headline figures from the Comet server vendor.
Finally, Zaid Al-Timimi has released XML Studio 7.3 which has Comet developer support.
Developers can now build and test real-time streaming mash-up applications. Version 7.3 embeds a copy of the upcoming <alt> Dynamic Mashup Server which uses a custom version of Grizzly, the Comet technology from Sun.
Tuesday, March 18th, 2008
Category: Comet
, JavaScript
, Library
Azer Koçulu thinks that you can create a comet application in 3 minutes with his new library pi.comet. It provides realtime data transfers between client and server.You can use pi.comet with any server side language.
The usage is very simple indeed:
JAVASCRIPT:
-
-
var request = new pi.comet();
-
request.environment.setUrl("push.php");
-
request.event.push = function(RESPONSE){
-
alert(RESPONSE);
-
};
-
request.send();
-
And the style of client side comet depends on the type of browser:
JAVASCRIPT:
-
-
scope.comet.constructor = function(){
-
this.environment.setName("piComet");
-
this.environment.setType(scope.env.ie?3:scope.env.opera?2:1);
-
this.environment.setTunnel(
-
this.environment.getType()==3?new ActiveXObject("htmlfile"):
-
this.environment.getType()==2?document.createElement("event-source"):
-
new scope.xhr
-
);
-
}
-
Monday, February 18th, 2008
Category: Comet
, Java
, JavaScript
, Library
Caplin Systems, creator of the Liberator Comet platform have announced a free version which can be used for non-commercial applications and for evaluation.
Liberator includes a high-performance Comet server, a JavaScript client library, and a Java server integration library.
There are many examples such as the subscriptions sample which shows a page with realtime updating information for a variety of equities and foreign exchange data.

This is how a subscriber looks in JavaScript:
HTML:
-
-
<script type="text/javascript" id="sl4b" src="/sl4b" rttpprovider="javascript"></script>
-
-
// class definition for SimpleSubscriber
-
function SimpleSubscriber(sObjectName)
-
{
-
// Store the object name as a member variable so it can be used later on; no subscription can
-
// take place until this object's ready() method has been called.
-
this.m_sObjectName = sObjectName;
-
-
// Invokes the initialise method on the base class (i.e. SL4B_AbstractSubscriber), this
-
// must be called within the constructor of all SL4B_AbstractSubscriber subclasses.
-
this.initialise();
-
}
-
-
// Defines SimpleSubscriber as a subclass of SL4B_AbstractSubscriber.
-
SimpleSubscriber.prototype = new SL4B_AbstractSubscriber;
-
-
// Overrides the ready() method from SL4B_AbstractSubscriber; once this method has been invoked
-
// it becomes safe to make object subscriptions.
-
SimpleSubscriber.prototype.ready = function() {
-
// Use the RTTP provider to setup the subscription; a reference to this object is passed in
-
// since it will be acting as the subscriber, and will receive the notification updates.
-
SL4B_Accessor.getRttpProvider().getObject(this, this.m_sObjectName);
-
};
-
-
// Overrides the recordUpdated() callback method from SL4B_AbstractSubscriber; this method will
-
// be invoked whenever new object data becomes available.
-
SimpleSubscriber.prototype.recordUpdated = function (sObjectName, sFieldName, sValue) {
-
// add code to process the record update here
-
}
-
-
// Creates a new SimpleSubscriber to receive streaming updates for /DEMO/YHOO.
-
new SimpleSubscriber("/DEMO/YHOO");
-
</script>
-
Tuesday, February 5th, 2008
Category: Comet
, Dojo
Roberto Saccon has taken the Dojo example program sketch, which itself "fully implements the idea of pipelining the drawing process based on sequential commands for adding, modifying or deleting objects" and has Cometized it:
Very little additional code was necessary to combine the chat app and the drawing app into a collaborative example app. I added a single line of code to the drawing app to let it publish its demands using Comet. Another line was added to the chat app for sending incoming drawing commands to the drawing application (any additional code only served to make things prettier, more readable, or easier to extend).
The application has been tested on ErlyComet (and there is also the source code), but there are no server-side dependencies, so in theory it should run equally well on any Bayeux-compliant Comet server. And there is also a short screencast.
What is missing to make such an example application suitable for real life tasks? A lot, of course: the whole server-side logic, for one. And deciding (automatically or based on human interaction) which incoming changes should be applied to the master document (like conflict resolution in version control systems, just in quasi-real time).
Very nicely done.

Friday, January 18th, 2008
Category: Comet
As JavaScript developers, we are used to years of hacks, as we try to push forward without browsers updating and helping us out. We are so stuck in this pragmatic thinking that we sometimes forget to pick our heads up.
Kris Zyp has taken some time to think about Comet, and instead of thinking about the next good hack, he takes that step back and dreams:
What if I had commit privileges on all the major browsers, the competence to add functionality in all the code bases, and wanted to add native Comet support in a form that was easily accessible to developers?
He ends up with a proposal that adds to good ole XHR:
With only a few simple XMLHttpRequest API additions, Comet communication could be realized with a native implementation that supports fast and efficient standards-based two-way asynchronous communication, with true server-delivered HTTP streaming and simple subscription requests, with the added benefit of client-delivered streaming and cached resource until updated capability. Developers could create Comet applications with a standard API without hacks. Communication could be standards-based, allowing current servers to easily implement the necessary features to handle communication.
It would look something like this:
JAVASCRIPT:
-
-
var cometXHR = new XMLHttpRequest;
-
cometXHR.open('POST','comet',true);
-
-
var xhr1 = new XMLHttpRequest;
-
cometXHR.addHttpChunk(xhr1);
-
xhr1.onreadystatechange=function(){...}
-
xhr.open('GET','/ticker1',true);
-
xhr.send();
-
-
var xhr2 = new XMLHttpRequest;
-
cometXHR.addHttpChunk(xhr2);
-
xhr2.onreadystatechange=function(){...}
-
xhr.open('GET','/ticker2',true);
-
xhr.send();
-
Kris gets into many of the details, and makes me with that someone would implement this as a Google Gear, so it could get pushed into the fabric of the Web by being on all browsers.

Monday, January 7th, 2008
Category: Comet
Greg Wilkins is marching a long with better and more performant Comet support as shown in his piece 20,000 Reasons Why Comet Scales:
After some recent optimizations, the Dojo Cometd implementation of the Bayeux protocol running on the Jetty web server can now handle up to 20,000 simultaneous users per server while maintaining sub-second latency.

This was done on "mid-sized Amazon EC2 virtual servers: 7.5 GB of memory, 2×2 EC2 Compute Units, 64-bit platform running Ubuntu 7.10 and Sun JVM 1.5.0_13. A single virtual machine was used as the Cometd server and between 1 and 3 virtual machines were used to generate the load of 20,000 clients."
Zimbra recently posted about how they switched to Jetty and why continuations was a major reason:
Jetty uses the Continuation pattern to suspend a blocked polling request and free the worker thread. By using Continuation, Jetty keeps impact on existing Web applications and Servlet related technologies to a minimum. Applications written according to the current Servlet specs can take advantage of Comet with trivial changes, and the Continuation mechanism for suspending and resuming of a request is most straightforward. Although Continuation is hardly the only way to implement Comet support, it's worth noting that other approaches typically will require writing asynchronous code at the application level which carries a signification application development cost.
In summary, we chose Jetty not only because it supports Comet in a scalable manner, but also because the Continuation implementation of Comet is least disruptive to existing Servlet based technologies.
Thursday, December 27th, 2007
Category: Articles
, Comet
Arena Albionu has written about Django and Comet using the Orbited Python event driven comet server.
The article walks through the hello world of Comet... a chat server. The JavaScript looks like this:
JAVASCRIPT:
-
-
function processGetPost()
-
{
-
var myajax=ajaxpack.ajaxobj
-