Showing posts with label Comet. Show all posts
Showing posts with label Comet. Show all posts

Nov 11, 2009

Runningman: Gears, Ajax, and Comet

In the GoogleLab API, there are several awesome examples of apps you can build using Gears. For those of you that don't know what Google Gears is, heres a brief history. Google experimented with offline applications and came to a few conclusions. As they developed offline-enabled applications, they typically found the following design flaws:
  • isolating the data layer
  • deciding which features to implement offline (connection strategy)
  • deciding on the app's modality
  • implementing data synchronization
What an offline application can do is allow a user to interact with a web-service and to be productive while a connection is unavailable. Gears localizes several server features to give the user as rich of an experience as possible. Items that are localized on the client side include a data switch, server data layer, local data later, database, and a sync engine. While that may seem like a lot of stress to put on the client side, they have modules included that lighten the work load and only marginally decrease the speed of the application. When a connection is made with a server, Gears uses either Ajax or Comet to transfer data.

So back to these cool applications. The one I read into was called Runningman. Runningman is a program designed for the Android OS that allows a runner to time their run and through the use of the phones GPS, track their path on a Google Map. The group working on the mountian biking website might benefit from this example, since they are doing something very similar.

The Runningman application includes Gears and contains a full code sample that you can download and manipulate on your own. They even have a full tutorial telling you have to write the program. Way cool! As you walk through the tutorial, they show you how Gears lets you create a desktop shortcut, use Comet to update data, use the Gears Localsever to operate offline, and much more.

Comet

This class is all about programming with Ajax. But Ajax isn't a programming language at all, its simply a methodology to connect asynchronously to a server using Javascript. Ajax isn't the only way to gain this functionality though. Ajax works by polling data from a server, but what if you wanted the server to push data to the browser? Thats where Comet comes in.


As you can see from the above image, Ajax relies on a request sent from the browser to the server. All of the arrows point from the browser to the server. In the Comet example, the arrows originate from the server and send data to the browser. There are two types of comet: streaming and long polling. Long Polling simply uses a regular Ajax request that remains open. Streaming uses one of two methods, Hidden IFrame or XMLHttpRequest Server Push. According to webreference.com, Long Polling is the way to go because it is so similar to Ajax and browsers/servers alike are commonly compatible with it.

A great how-to tutorial can be found at webreference.com. You will see that Comet shares a lot of similarities with Ajax. Examples of programs using Comet include Gmail Chat and several sports websites 'Live Score' apps. Btw, anyone that already knows a lot about Comet should check out the Wikipedia page for it. It has a lot of warning messages on the top! Disclaimer: None of the content for this post was found on Wikipedia.