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.
Comet sounds interesting. I'm still going to go research it some more and read more from the link you posted, but thanks for the intro to this service I've never heard of before! I'm struggling to see where it would be beneficial other than sports scoring Websites though. I mean how can the server give information to a user if the user hasn't asked for anything yet? Interesting...I'm going to go read more on it now to see if I can figure out more about it.
ReplyDeleteCool post Colin. I'm a little confused though. Is the only difference beween ajax and comet (long polliing) is that it remains open to gets a quicker responce from the server? Thus eliminating the step of requesting from the browser to the server?
ReplyDeleteJustin,
ReplyDeleteThe main difference is, as Matt mentioned, that the server sends unsolicited information to the browser. So their is a pre-determined need to deliver information to the browser, and the server updates the browser as needed. In long polling, the connection remains open simply to enable this method of communication. It is just as fast as Ajax since the request is still asynchronous and doesn't require the entire page to refresh.
As for Matt's comment, I too will be looking into Comet more. I happened to read about it while looking up stuff on Google Gears and wanted to see what they were talking about.