Activate your free membership today | Log-in

Tuesday, July 8th, 2008

Legitimizing Comet with HTML 5 WebSocket

Category: Comet

JAVASCRIPT:
  1.  
  2. var conn = new WebSocket("ws://www.example.com/livedemo");
  3.  
  4. conn.onopen = function(evt) { alert("Conn opened"); }
  5. conn.onread = function(evt) { alert("Read: " + evt.data); }
  6. conn.onclose = function(evt) { alert("Conn closed"); }
  7.  
  8. conn.send("Hello World")
  9.  

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.

Posted by Dion Almaer at 6:09 am
9 Comments

++++-
4.6 rating from 24 votes

Tuesday, July 1st, 2008

TCPSocket: Sockets in the browser

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:
  1.  
  2. var conn = new TCPSocket(hostname, port)
  3.  
  4. conn.onopen = function() { alert('connection opened!') }
  5. conn.onread = function(data) { alert('RECEIVE: ' + data) }
  6. conn.onclose = function(data) { alert('connection closed!') }
  7.  
  8. conn.send('Hello World');
  9.  

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.

Posted by Dion Almaer at 12:50 pm
3 Comments

++++-
4.5 rating from 16 votes

Monday, May 12th, 2008

Live Chess with Comet

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).

Posted by Dion Almaer at 9:44 am
5 Comments

++++-
4.7 rating from 15 votes

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.8 rating from 13 votes

Tuesday, March 18th, 2008

pi.comet: simple comet library

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:
  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.5 rating from 22 votes

Monday, February 18th, 2008

Liberator Comet Platform: Free Edition

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.

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 21 votes

Tuesday, February 5th, 2008

Collaborative Drawing with Sketch

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.

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 24 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