Activate your free membership today | Log-in

Friday, March 28th, 2008

Comet Roundup: Gazing, Battles, and Protocols

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.

Posted by Dion Almaer at 5:56 am
Comment here

++---
2.6 rating from 12 votes

Tuesday, March 18th, 2008

pi.comet: simple comet library

Category: JavaScript, Library, Comet

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:
  1.  
  2. var request = new pi.comet();
  3. request.environment.setUrl("push.php");
  4. request.event.push = function(RESPONSE){
  5.           alert(RESPONSE);
  6. };
  7. request.send();
  8.  

And the style of client side comet depends on the type of browser:

JAVASCRIPT:
  1.  
  2. scope.comet.constructor = function(){
  3.         this.environment.setName("piComet");
  4.         this.environment.setType(scope.env.ie?3:scope.env.opera?2:1);
  5.         this.environment.setTunnel(
  6.                 this.environment.getType()==3?new ActiveXObject("htmlfile"):
  7.                 this.environment.getType()==2?document.createElement("event-source"):
  8.                 new scope.xhr
  9.         );
  10. }
  11.  

Posted by Dion Almaer at 7:43 am
6 Comments

++++-
4.6 rating from 21 votes

Monday, February 18th, 2008

Liberator Comet Platform: Free Edition

Category: JavaScript, Java, Library, Comet

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.

Liberator Subscriptions

This is how a subscriber looks in JavaScript:

HTML:
  1.  
  2. <script type="text/javascript" id="sl4b" src="/sl4b" rttpprovider="javascript"></script>
  3. <script type="text/javascript">
  4. // class definition for SimpleSubscriber
  5. function SimpleSubscriber(sObjectName)
  6. {
  7.    // Store the object name as a member variable so it can be used later on; no subscription can
  8.    // take place until this object's ready() method has been called.
  9.    this.m_sObjectName = sObjectName;
  10.  
  11.    // Invokes the initialise method on the base class (i.e. SL4B_AbstractSubscriber), this
  12.    // must be called within the constructor of all SL4B_AbstractSubscriber subclasses.
  13.    this.initialise();
  14. }
  15.  
  16. // Defines SimpleSubscriber as a subclass of SL4B_AbstractSubscriber.
  17. SimpleSubscriber.prototype = new SL4B_AbstractSubscriber;
  18.  
  19. // Overrides the ready() method from SL4B_AbstractSubscriber; once this method has been invoked
  20. // it becomes safe to make object subscriptions.
  21. SimpleSubscriber.prototype.ready = function() {
  22.    // Use the RTTP provider to setup the subscription; a reference to this object is passed in
  23.    // since it will be acting as the subscriber, and will receive the notification updates.
  24.    SL4B_Accessor.getRttpProvider().getObject(this, this.m_sObjectName);
  25. };
  26.  
  27. // Overrides the recordUpdated() callback method from SL4B_AbstractSubscriber; this method will
  28. // be invoked whenever new object data becomes available.
  29. SimpleSubscriber.prototype.recordUpdated = function (sObjectName, sFieldName, sValue) {
  30.    // add code to process the record update here
  31. }
  32.  
  33. // Creates a new SimpleSubscriber to receive streaming updates for /DEMO/YHOO.
  34. new SimpleSubscriber("/DEMO/YHOO");
  35. </script>
  36.  

Posted by Dion Almaer at 5:25 am
2 Comments

++++-
4 rating from 20 votes

Tuesday, February 5th, 2008

Collaborative Drawing with Sketch

Category: Dojo, Comet

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.

Comet Sketch

Posted by Dion Almaer at 7:48 am
2 Comments

++++-
4.3 rating from 11 votes

Friday, January 18th, 2008

Native Comet Support for Browsers

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:
  1.  
  2. var cometXHR = new XMLHttpRequest;
  3. cometXHR.open('POST','comet',true);
  4.  
  5. var xhr1 = new XMLHttpRequest;
  6. cometXHR.addHttpChunk(xhr1);
  7. xhr1.onreadystatechange=function(){...}
  8. xhr.open('GET','/ticker1',true);
  9. xhr.send();
  10.  
  11. var xhr2 = new XMLHttpRequest;
  12. cometXHR.addHttpChunk(xhr2);
  13. xhr2.onreadystatechange=function(){...}
  14. xhr.open('GET','/ticker2',true);
  15. xhr.send();
  16.  

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.

Posted by Dion Almaer at 9:26 am
7 Comments

+++--
3.8 rating from 23 votes

Monday, January 7th, 2008

20,000 Reasons that Comet Scales

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.

20000 Reasons Comet Scales

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.

Posted by Dion Almaer at 2:14 pm
8 Comments

++++-
4.3 rating from 18 votes

Thursday, December 27th, 2007

Django and Comet

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:
  1.  
  2. function processGetPost()
  3.         {
  4.         var myajax=ajaxpack.ajaxobj
  5.         var myfiletype=ajaxpack.filetype
  6.         if (myajax.readyState == 4)
  7.                 { //if request of file completed
  8.                 if (myajax.status==200 || window.location.href.indexOf("http")==-1)
  9.                         { //if request was successful or running script locally
  10.                         if (myfiletype=="txt")
  11.                         alert(myajax.responseText)
  12.                         else
  13.                         alert(myajax.responseXML)
  14.                         }
  15.                 }
  16.         }
  17.  
  18.  
  19. function connect()
  20. {
  21.   var nick = document.getElementById('nickname').value;
  22.   Orbited.connect(chat_event, nick, "/chat", "0");
  23.   ajaxpack.getAjaxRequest("/join/" + nick + "/", "", processGetPost, "txt");
  24. }
  25.  
  26.  
  27. chat_event = function(data) {
  28.   var chat_box = document.getElementById('box');
  29.   var div = window.parent.document.createElement('div');
  30.   div.className = "event";
  31.   div.innerHTML = data;
  32.   chat_box.appendChild(div);
  33.   chat_box.scrollTop = chat_box.scrollHeight;
  34. }
  35.  
  36. function send_msg() {
  37.   var msg = document.getElementById('chat').value;
  38.   var nick = document.getElementById('nickname').value;
  39.   ajaxpack.getAjaxRequest("/send/" + nick + "/" + msg + "/", "", processGetPost, "txt");
  40. }
  41.  

Posted by Dion Almaer at 12:08 am
2 Comments

+++--
3.3 rating from 13 votes

Thursday, December 13th, 2007

The Future of Comet: Part 1, Comet Today

Category: Comet

Jacob Rus keeps the run of great content on Comet Daily by talking about the the future of Comet: Part 1: Comet Today. Jacob discusses the hacks that we use for Comet, compared to the server-sent events and event-source specs that are finally getting implemented. He then goes through the current trade-offs behind current solutions:

  • “Forever-frame” iframe streaming
  • htmlfile ActiveX object
  • XHR multipart
  • XHR streaming
  • XHR long-polling
  • Script tag long-polling (“CometP”)
  • Flash and other plugins

With this impressive list of transports, we can cover all recent browsers (IE 5+, Safari 1.3+, Firefox 1.0+; Opera 8.5+ as described next time) without unseemly side-effects, using our choice of streaming or long-polling, and can support browsers back much further than that, with a few usability niggles. Unfortunately, however, this requires careful implementation of our server code and browser-side JavaScript, which must coordinate to agree on a transport. This coordination problem, along with browser’s cross-domain security policies, prevent us from using real-time sources in the kinds of mashups built from other web services. The barriers to entry for Comet are much higher than for non-real-time content, and success relies on loopholes in existing browser objects. Wouldn’t it be nice if every browser used the same mechanism, which could stream events across domains securely and efficiently, and web authors could in turn write straight-forward HTML and JavaScript, and send but a single format from the server? Stay tuned for part 2, which plots a course to such a future.

Posted by Dion Almaer at 6:54 am
1 Comment

+++--
3.5 rating from 23 votes

Friday, December 7th, 2007

Comet. Not as painful as you think!

Category: Comet

Simon Willison was worried that the amount of complexity involved with Comet meant it was out of bounds to all but the most dedicated JavaScript hackers but after playing with it, concluded:

I’m pleased to admit that I was wrong: Comet is probably about 90% of the way to being usable for mainstream projects, and the few remaining barriers (Bayeux authentication chief amongst them) are likely to be solved before too long. I expect to see many more sites start deploying Comet powered features over the next twelve months.

For Simon's presentation he built the slideshow itself as a Comet app. He could move the slideshow forwards and backwards, and anyone connected would also see the slides move. A nice touch. He used Jetty as the web server, and Dojo as the client:

JAVASCRIPT:
  1.  
  2. dojo.require("dojox.cometd");
  3. jQuery(function($) {
  4.     dojox.cometd.init("http://example.com/cometd");
  5.     dojox.cometd.subscribe("/slideshow/change", function(comet) {
  6.         $('#currentSlide').attr('src', comet.data.src);
  7.     });
  8. });
  9.  
  10. function publishSlide(src) {
  11.     dojox.cometd.publish("/slideshow/change", {
  12.         'src': src
  13.     });
  14. }
  15.  

Posted by Dion Almaer at 6:49 am
6 Comments

++---
2.8 rating from 58 votes

Wednesday, December 5th, 2007

Cross Site Scripting Joy: XSS in detail

Category: Security, Comet

In Cross Site Scripting Joy, Andrew Betts has taken the time to go into real detail on XSS and the fun and frolics that we have with the Same Origin Policy and beyond:

So the battle over XSS as a security problem has moved on from the same origin policy, but same origin remains a massive obstacle to development of useful non-malicious services, and that’s particularly true of Comet, because there are typically two servers involved in any comet setup: a web server like Apache, and a comet server like Meteor or Orbited.

There are essentially three choices for making these two servers play together:

  1. marry them: have one server that serves both your Comet connections and the standard ones (including any dynamically generated content);
  2. have a regular web server with a Comet server sitting in front of it, so all connections are made to the Comet server, and it proxies the non-comet connections to the web server;
  3. have both the Comet and the regular web server exposed to the web, and request applicable content from each one.

Andrew then decided to write a bunch of tests (38 in fact) to see how the SOP is implemented in various browsers, and ended up with the following thorough information:

XSS Tests

Posted by Dion Almaer at 6:45 am
Comment here

++++-
4.3 rating from 24 votes

Tuesday, November 27th, 2007

Grizzly attacks: DWR’s Reverse Ajax to support The Comet Implementation

Category: Java, Comet

Jean-Francois Arcand of the Tomcat team has implemented DWR Reverse Ajax in Grizzly:

The Grizzly framework has been designed to help developers to take advantage of the Java™ NIO API. Originally developed under the GlassFish umbrella, the framework is now available as a standalone project. Grizzly goals is to help developers to build scalable and robust servers using NIO.

From DWR you can grab continuations in Grizzly via:

JAVA:
  1.  
  2. GrizzlyContinuation continuation = Continuation.getContinuation();
  3. continuation.suspend(timeout);
  4.  

Posted by Dion Almaer at 6:36 am
Comment here

++++-
4.5 rating from 15 votes

Tuesday, November 20th, 2007

HTTP Streaming and Internet Explorer

Category: IE,