Comet (programming): Difference between revisions
m →Alternatives: ref |
m unbalanced curley brackets |
||
(442 intermediate revisions by more than 100 users not shown) | |||
Line 1: | Line 1: | ||
{{short description|Web application model}} |
|||
{{Otheruses2|Comet}} |
|||
'''Comet''' is a [[web application]] model in which a long-held [[HTTPS]] request allows a [[web server]] to [[Push technology|push]] data to a [[web browser|browser]], without the browser explicitly requesting it.<ref name="MASH">{{cite web | url = http://www.infoworld.com/d/developer-world/ajax-alliance-recognizes-mashups-559 | title = AJAX alliance recognizes mashups | access-date = 2010-10-20 | last = Krill | first = Paul | date = September 24, 2007 | publisher = [[InfoWorld]]}}</ref><ref name="CRANG">{{cite book|title=Comet and Reverse Ajax: The Next-Generation Ajax 2.0|last2=McCarthy|first2=Phil|date=October 13, 2008|publisher=[[Apress]]|isbn=978-1-59059-998-3|last1=Crane|first1=Dave}}<!--| accessdate = 2010-10-20 --></ref> ''Comet'' is an [[umbrella term]], encompassing multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as [[JavaScript]], rather than on non-default plugins. The Comet approach differs from the [[World Wide Web#Function|original model of the web]], in which a browser requests a complete web page at a time.<ref name = "WRC" /> |
|||
{{Article issues|date=October 2008| cleanup = June 2008 |
|||
| OR = June 2008 |
|||
| peacock = June 2008 |
|||
| self-published = June 2008 |
|||
| advert = May 2008 |
|||
}} |
|||
In [[web development]], '''Comet''' is a [[neologism]] to describe a [[web application]] model in which a long-held [[HTTP]] request allows a [[web server]] to [[Push technology|push]] data to a browser, without the browser explicitly requesting it. Comet is an [[umbrella term]] for multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as [[JavaScript]], rather than on non-default plugins. {{Or|date=March 2009}} |
|||
The use of Comet techniques in [[web development]] predates the use of the word ''Comet'' as a [[neologism]] for the collective techniques. Comet is known by several other names, including |
|||
In theory, the Comet approach differs from the [[World Wide Web#How the Web works|original model of the web]], in which a browser requests a complete web page or chunks of data to update a web page. However in practice, Comet applications typically use [[Ajax (programming)|Ajax]] with [[Push_technology#Long_polling|long polling]] to detect new information on the server. The concept predates the coining of the neologism, and is known by several other names, including |
|||
''Ajax Push'',<ref>{{cite speech |
''Ajax Push'',<ref>{{cite speech |
||
| title = Ajax Push (a.k.a. Comet) with Java Business Integration (JBI) |
| title = Ajax Push (a.k.a. Comet) with Java Business Integration (JBI) |
||
Line 18: | Line 11: | ||
| location = [[JavaOne]] 2007, [[San Francisco, California]] |
| location = [[JavaOne]] 2007, [[San Francisco, California]] |
||
| url = http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-8434&yr=2007&track=7 |
| url = http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-8434&yr=2007&track=7 |
||
| |
| access-date = 2008-06-10 |
||
}}</ref><ref name="ice">{{cite web |
}}</ref><ref name="ice">{{cite web |
||
|url=http://www. |
|url=http://www.icesoft.org/java/projects/ICEfaces/ajax-push.jsf |
||
|title=Ajax Push |
|title=Ajax Push |
||
|publisher=ICEfaces.org |
|publisher=ICEfaces.org |
||
| access-date = 2014-10-23 |
|||
|language=English |
|||
|format=html |
|||
| accessdate = 2008-07-21 |
|||
}}</ref> |
}}</ref> |
||
'' |
''Reverse Ajax'',<ref>{{cite book |
||
|title = Comet and Reverse Ajax: The Next Generation Ajax 2.0 |
|title = Comet and Reverse Ajax: The Next Generation Ajax 2.0 |
||
|first = Dave |
|first = Dave |
||
|last = Crane |
|last = Crane |
||
| |
|author2=McCarthy, Phil |
||
|publisher = Apress |
|publisher = Apress |
||
|isbn = |
|isbn = 978-1-59059-998-3 |
||
| |
|date=July 2008 |
||
}}</ref> ''Two-way-web'',<ref name="ajax-dp-oreilly"/> ''HTTP Streaming'',<ref name="ajax-dp-oreilly">{{cite book |
|||
|month = July |
|||
|language = English |
|||
}}</ref> ''Two-way-web'',<ref name="ajax-dp-oreilly"/> ''HTTP Streaming''<ref name="ajax-dp-oreilly">{{cite book |
|||
|title=Ajax Design Patterns |
|title=Ajax Design Patterns |
||
|first=Michael |
|first=Michael |
||
|last= |
|last=Mahemoff |
||
|publisher=[[O'Reilly Media]] |
|publisher=[[O'Reilly Media]] |
||
| |
|date=June 2006 |
||
|isbn=0-596-10180-5 |
|||
|month=June |
|||
|pages=[https://archive.org/details/ajaxdesignpatter00mahe/page/19 19; 85] |
|||
|language=English |
|||
|isbn=0596101805 |
|||
|pages=19; 85 |
|||
|chapter=Web Remoting |
|chapter=Web Remoting |
||
|chapter-url-access=registration |
|||
|chapter-url=https://archive.org/details/ajaxdesignpatter00mahe/page/19 |
|||
}}</ref> and |
}}</ref> and |
||
''[[ |
''[[HTTP push|HTTP server push]]''<ref>{{cite web |
||
|url = http://www.bluishcoder.co.nz/2005/11/more-on-ajax-and-server-push.html |
|url = http://www.bluishcoder.co.nz/2005/11/more-on-ajax-and-server-push.html |
||
|title = More on Ajax and server push |
|title = More on Ajax and server push |
||
Line 56: | Line 45: | ||
|last = Double |
|last = Double |
||
|date = 2005-11-05 |
|date = 2005-11-05 |
||
| |
|access-date = 2008-05-05 |
||
}} |
}} |
||
</ref> |
</ref> |
||
among others.<ref>{{cite web |
among others.<ref>{{cite web |
||
|url = http://www.obviously.com/tech_tips/slow_load_technique |
|url = http://www.obviously.com/tech_tips/slow_load_technique |
||
|title = The Slow Load Technique/Reverse AJAX |
|title = The Slow Load Technique/Reverse AJAX |
||
|work = Simulating Server Push in a Standard Web Browser |
|work = Simulating Server Push in a Standard Web Browser |
||
|first = Bryce |
|first = Bryce |
||
|last = Nesbitt |
|last = Nesbitt |
||
|date = 2005-11-01 |
|date = 2005-11-01 |
||
| |
|access-date = 2008-05-06 |
||
|url-status = dead |
|||
|archive-url = https://web.archive.org/web/20060208041559/http://www.obviously.com/tech_tips/slow_load_technique |
|||
|archive-date = 2006-02-08 |
|||
}} |
}} |
||
</ref> The term ''Comet'' is not an acronym, but was coined by Alex Russell in his 2006 [[blog]] post.<ref>{{cite web |
|||
</ref> |
|||
|url = http://infrequently.org/2006/03/comet-low-latency-data-for-the-browser/ |
|||
|title = Comet: Low Latency Data for the Browser |
|||
|first = Alex |
|||
|last = Russell |
|||
|date = 2006-03-04 |
|||
|access-date = 2014-11-02 |
|||
}}</ref>{{citation needed|date=June 2023}} |
|||
In recent years, the standardisation and widespread support of [[WebSocket]] and [[Server-sent events]] has rendered the Comet model obsolete. |
|||
== Implementations == |
|||
{{Expert-subject|Technology|section|date=October 2008}} |
|||
<!-- TODO: Image of Comet, showing both streaming and Ajax long polling --> |
|||
==History== |
|||
Comet is an [[umbrella term]] for technologies that attempt to eliminate both the limitations of the [[World_Wide_Web#How_the_Web_works|page-by-page web model]] and traditional [[polling (computer science)|polling]]. Comet-like applications offer real-time interaction by relying on a persistent HTTP connection (or where not possible a long lasting HTTP connection) to provide the browser with updates as designated by the web application. |
|||
Since browsers and proxies are not designed with server events in mind, web application developers have tried to work around several unintended side-effects to implement Comet-like behavior, each with different benefits and drawbacks. In particular, the HTTP 1.1 specification states that a browser should not have more than 2 simultaneous connections with a web server.<ref>HTTP 1.1 specification, [http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4 section 8.1.4]. W3C. Retrieved [[30 November]] [[2007]]</ref> However, holding one connection open for real-time events has a negative impact on browser usability. The browser may be blocked from sending a new request while it still loads, for example, a series of images. This can be worked around by creating a distinct [[hostname]] for real-time information, which is an alias for the same physical server. |
|||
===Early Java applets=== |
|||
Specific methods of implementing Comet fall into two major categories: streaming and long polling. |
|||
The ability to embed [[Java applet]]s into browsers (starting with [[Netscape Navigator 2]].0 in March 1996<ref>{{cite web |url=http://www27.netscape.com/comprod/products/navigator/version_2.0/index.html |title=Netscape.com |access-date=2017-08-16 |url-status=bot: unknown |archive-url=https://web.archive.org/web/19961115203505/http://www27.netscape.com/comprod/products/navigator/version_2.0/index.html |archive-date=November 15, 1996 }}</ref>) made two-way sustained communications possible, using a raw [[Transmission Control Protocol|TCP]] socket<ref>[http://java.sun.com/j2se/1.4.2/docs/enwiki/api/java/net/Socket.html "java.net.Socket (Java 2 Platform SE v1.4.2)"] {{webarchive |url=https://web.archive.org/web/20090519063251/http://java.sun.com/j2se/1.4.2/docs/enwiki/api/java/net/Socket.html |date=May 19, 2009 }}</ref> to communicate between the browser and the server. This socket can remain open as long as the browser is at the document hosting the applet. Event notifications can be sent in any format{{snd}} text or binary{{snd}} and decoded by the applet. |
|||
===The first browser-to-browser communication framework=== |
|||
=== Streaming === |
|||
The very first application using browser-to-browser communications was Tango Interactive,<ref>{{Cite web |
|||
In an application using streaming Comet, the browser opens a single persistent connection to the server for all Comet events, which is handled incrementally on the browser side. Each time the server sends a new event, the browser interprets it, but neither side closes the connection. Specific techniques for accomplishing streaming Comet include the following. |
|||
| url = http://surface.syr.edu/cgi/viewcontent.cgi?article=1076&context=npac |
|||
| title = TANGO - a Collaborative Environment for the World-Wide Web |
|||
| last = Beca |
|||
| first = Lukasz |
|||
| date = 1997 |
|||
| website = Syracuse University SURFACE |
|||
| publisher = Northeast Parallel Architecture Center, College of Engineering and Computer Science |
|||
| access-date = 27 February 2016 |
|||
}}</ref>{{failed verification|date=December 2017}} implemented in 1996–98 at the Northeast Parallel Architectures Center ([http://surface.syr.edu/npac/ NPAC]) at [[Syracuse University]] using [[DARPA]] funding. TANGO architecture has been patented by Syracuse University.<ref>{{Citation|last1 = Podgorny|first1 = Marek|title = United States Patent: 6078948 - Platform-independent collaboration backbone and framework for forming virtual communities having virtual rooms with collaborative sessions|date = June 20, 2000|url = http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%252Fnetahtml%252FPTO%252Fsearch-bool.html&r=14&f=G&l=50&co1=AND&d=PTXT&s1=Podgorny.INNM.&OS=IN/Podgorny&RS=IN/Podgorny|last2 = Beca|last3 = Cheng|last4 = Fox|last5 = Jurga|last6 = Olszewski|last7 = Sokolowski|last8 = Walczak|last9 = PL|first2 = Lukasz|first3 = Gang|first4 = Geoffrey C.|first5 = Tomasz|first6 = Konrad|first7 = Piotr|first8 = Krzysztof|access-date = 2016-02-27|archive-date = 2017-05-09|archive-url = https://web.archive.org/web/20170509022914/http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%252Fnetahtml%252FPTO%252Fsearch-bool.html&r=14&f=G&l=50&co1=AND&d=PTXT&s1=Podgorny.INNM.&OS=IN/Podgorny&RS=IN/Podgorny|url-status = dead}}</ref> TANGO framework has been extensively used as a distance education tool.<ref>{{Cite web |
|||
| url = https://www.dsc.soic.indiana.edu/sites/default/files/tr_9921.pdf |
|||
| title = Experiences with Using TANGO Interactive in a Distributed Workshop |
|||
| last = Baer |
|||
| first = Troy |
|||
| date = 1999 |
|||
| website = CEWES Major Shared Resource Center |
|||
| publisher = CEWES MSRC/PET TR/99-21 |
|||
| access-date = 27 February 2016 |
|||
| archive-date = 8 March 2021 |
|||
| archive-url = https://web.archive.org/web/20210308093626/https://www.dsc.soic.indiana.edu/sites/default/files/tr_9921.pdf |
|||
| url-status = dead |
|||
}}</ref> The framework has been commercialized by [http://www.collabworx.com CollabWorx] and used in a dozen or so Command&Control and Training applications in the United States Department of Defense{{citation needed|date=December 2017}}. |
|||
=== |
===First Comet applications=== |
||
The first set of Comet implementations dates back to 2000,<ref name="CometDaily_History">{{cite web |url=http://cometdaily.com/2007/10/19/comet-and-push-technology/ |title=CometDaily: Comet and Push Technology |access-date=2007-12-15 |archive-url=https://web.archive.org/web/20071113174053/http://cometdaily.com/2007/10/19/comet-and-push-technology/ |archive-date=2007-11-13 |url-status=dead }}</ref>{{unreliable source?|date=November 2017}} with the [[Pushlets]], [[Lightstreamer]], and KnowNow projects. [[Pushlets]], a framework created by Just van den Broecke, was one of the first<ref name="pushlets-javaworld">Just van den Broecke (1 March 2000). “[http://www.javaworld.com/article/2076063/java-web-development/pushlets--send-events-from-servlets-to-dhtml-client-browsers.html Pushlets: Send events from servlets to DHTML client browsers] {{Webarchive|url=https://web.archive.org/web/20140804175811/http://www.javaworld.com/article/2076063/java-web-development/pushlets--send-events-from-servlets-to-dhtml-client-browsers.html |date=2014-08-04 }}”. JavaWorld. Retrieved 1 August 2014.</ref> open source implementations. Pushlets were based on server-side Java servlets, and a client-side JavaScript library. Bang Networks{{snd}} a [[Silicon Valley]] start-up backed by [[Netscape]] co-founder [[Marc Andreessen]]{{snd}} had a lavishly-financed attempt to create a real-time push standard for the entire web.<ref>{{cite web |
|||
A basic technique for dynamic web application is to use a hidden [[IFrame]] HTML element (an ''inline frame'', which allows a website to embed one HTML document inside another). This invisible IFrame is sent as a [[Chunked transfer encoding|chunked]] block, which implicitly declares it as infinitely long (sometimes called “forever frame”). As events occur, the iframe is gradually filled with <code>script</code> tags, containing JavaScript to be executed in the browser. Because browsers render HTML pages incrementally, each <code>script</code> tag is executed as it is received.<ref name="ajaxoreilly">{{cite book |
|||
|url=http://news.cnet.com/2100-1023-255088.html |
|||
| last = Holdener III |
|||
|title=Will the "refresh" button become obsolete? |
|||
| first = Anthony T. |
|||
|last=Borland |
|||
| title = Ajax: The Definitive Guide |
|||
|first=John |
|||
| publisher = [[O'Reilly Media]] |
|||
|date=2001-04-01 |
|||
| year = 2008 |
|||
|publisher=[[CNET Networks]] |
|||
| month = January |
|||
|access-date=2008-07-22 |
|||
| isbn = 0596528388 |
|||
| chapter = Page Layout with Frames that Aren't |
|||
| page = 320 |
|||
}}</ref> |
}}</ref> |
||
In April 2001, Chip Morningstar began developing a Java-based (J2SE) web server which used two HTTP sockets to keep open two communications channels between the custom HTTP server he designed and a client designed by [[Douglas Crockford]]; a functioning demo system existed as of June 2001.{{citation needed|date=February 2020}} The server and client used a messaging format that the founders of State Software, Inc. assented to coin as [[JSON]] following Crockford's suggestion. The entire system, the client libraries, the messaging format known as JSON and the server, became the State Application Framework, parts of which were sold and used by Sun Microsystems, Amazon.com, EDS and Volkswagen.{{citation needed|date=February 2020}} |
|||
One benefit of the IFrame method is that it works in every common browser. Two downsides of this technique are the lack of a reliable error handling method, and the impossibility of tracking the state of the request calling process.<ref name="ajaxoreilly"/> |
|||
In March 2006, [[software engineer]] Alex Russell coined the term Comet in a post on his personal blog.<ref name="alex_comet">Alex Russell (3 March 2006). “[http://alex.dojotoolkit.org/?p=545 Comet: Low Latency Data for the Browser] {{Webarchive|url=https://web.archive.org/web/20080812034003/http://alex.dojotoolkit.org/?p=545 |date=2008-08-12 }}”. Alex Russell’s blog. Retrieved 29 November 2007.</ref> The new term was a play on [[Ajax (programming)|Ajax]] ([[Ajax (cleanser)|Ajax]] and [[Comet (cleanser)|Comet]] both being common household cleaners in the USA).<ref>{{cite web |
|||
==== XMLHttpRequest ==== |
|||
|url=http://www.eweek.com/c/a/Application-Development/Microsoft-Scrubs-Comet-from-AJAX-Tool-Set/ |
|||
The [[XMLHttpRequest]] (XHR) object, the main tool used by Ajax applications for browser–server communication, can also be pressed into service for server–browser Comet messaging, in a few different ways. |
|||
|title=Microsoft Scrubs Comet from AJAX Tool Set |
|||
|last=K. Taft |
|||
|first=Darryl |
|||
|date=2006-05-12 |
|||
|publisher=eWEEK.com |
|||
|access-date=2008-07-21 |
|||
}}</ref><ref>[http://en.oreilly.com/oscon2008/public/schedule/detail/3048 Orbited: Enabling Comet for the Masses: OSCON 2008 - O'Reilly Conferences, July 21 - 25, 2008, Portland, Oregon<!-- Bot generated title -->]</ref><ref>[http://www.web2journal.com/read/457966.htm Enterprise Comet & Web 2.0 Live Presentation<!-- Bot generated title -->] {{webarchive|url=https://web.archive.org/web/20080520222527/http://www.web2journal.com/read/457966.htm |date=2008-05-20 }}</ref> |
|||
In 2006, some applications exposed those techniques to a wider audience: [[Meebo]]’s multi-protocol web-based chat application enabled users to connect to [[AOL Instant Messenger|AOL]], [[Yahoo! Messenger|Yahoo]], and [[MSN Messenger|Microsoft]] chat platforms through the browser; Google added web-based chat to [[Gmail]]; [[JotSpot]], a startup since acquired by Google, built Comet-based real-time collaborative document editing.<ref>Dion Almaer (29 September 2005). “[http://ajaxian.com/archives/jotspot-live-live-group-note-taking Jotspot Live: Live, group note-taking]” (interview with Abe Fettig). Ajaxian. Retrieved 15 December 2007. <br>Matt Marshall (15 December 2006). “[https://venturebeat.com/2006/12/15/renkoo-launches-just-in-time-to-schedule-holiday-cocktails/ Renkoo launches event service — in time to schedule holiday cocktails]”. Venture Beat. Retrieved 15 December 2007.</ref> New Comet variants were created, such as the Java-based [[ICEfaces]] [[JavaServer Faces|JSF]] framework (although they prefer the term "''Ajax Push''"<ref name="ice"/>). Others that had previously used Java-applet based transports switched instead to pure-JavaScript implementations.<ref>Clint Boulton (27 December 2005). “[http://www.devxnews.com/article.php/3573506/ Startups Board the AJAX Bandwagon]”. DevX News. Retrieved 18 February 2008.</ref> |
|||
In 1995, [[Netscape Navigator]] added a feature called “server push”, which allowed servers to send new versions of an image or HTML page to that browser, as part of a [[MIME#Multipart messages|multipart]] HTTP response (see [[#History|History]] section, below), using the content type <code>multipart/x-mixed-replace</code>. Since 2004, [[Gecko (layout engine)|Gecko]]-based browsers such as [[Mozilla Firefox|Firefox]] accept multipart responses to XHR, which can therefore be used as a streaming Comet transport.<ref>Johnny Stenback, et al. (March–April 2004). “[http://bugzilla.mozilla.org/show_bug.cgi?id=237319 Bug 237319 – Add support for server push using <code>multipart/x-mixed-replace</code> with XMLHttpRequest]”. Mozilla bug tracking. Retrieved [[29 November]] [[2007]]. Also see:<br/> Alex Russell ([[6 August]] [[2005]]). “[http://alex.dojotoolkit.org/?p=503 Toward server-sent data w/o iframes]”. Alex Russell’s blog. Retrieved [[29 November]] [[2007]].</ref> On the server side, each message is encoded as a separate portion of the multipart response, and on the client, the [[callback (computer science)|callback function]] provided to the XHR <code>onreadystatechange</code> function will be called as each message arrives. This functionality is only included in Gecko-based browsers, though there is discussion of adding it to Webkit.<ref>Rob Butler, et al. (June 2006). “[http://bugs.webkit.org/show_bug.cgi?id=14392 Bug 14392: Add support for <code>multipart/x-mixed-replace</code> to XMLHttpRequest]”. Webkit bug tracking. Retrieved [[29 November]] [[2007]].</ref> |
|||
==Implementations== |
|||
Instead of creating a multipart response, and depending on the browser to transparently parse each event, it is also possible to generate a custom data format for an XHR response, and parse out each event using browser-side JavaScript, relying only on the browser firing the <code>onreadystatechange</code> callback each time it receives new data. |
|||
Comet applications attempt to eliminate the limitations of the [[World Wide Web#Function|page-by-page web model]] and traditional [[polling (computer science)|polling]] by offering two-way sustained interaction, using a persistent or long-lasting HTTP connection between the server and the client. Since browsers and proxies are not designed with server events in mind, several techniques to achieve this have been developed, each with different benefits and drawbacks. The biggest hurdle is the [[Hypertext Transfer Protocol|HTTP]] 1.1 specification, which states "this specification... encourages clients to be conservative when opening multiple connections".<ref>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing, [http://tools.ietf.org/html/rfc7230#section-6.4 section 6.4]. IETF. Retrieved 2014-07-29</ref> Therefore, holding one connection open for real-time events has a negative impact on browser usability: the browser may be blocked from sending a new request while waiting for the results of a previous request, e.g., a series of images. This can be worked around by creating a distinct [[hostname]] for real-time information, which is an alias for the same physical server. This strategy is an application of domain sharding. |
|||
Specific methods of implementing Comet fall into two major categories: streaming and [[long polling]]. |
|||
=== Ajax with long polling === |
|||
===Streaming=== |
|||
None of the above streaming transports works across all modern browsers without causing negative side-effects in any—forcing Comet developers to implement several complex streaming transports, switching between them depending on the browser. Consequently many Comet applications instead opt for long polling, which is easier to implement on the browser side, and works, at minimum, in every browser that supports XHR. As the name suggests, long polling requires the client to poll the server for an event (or set of events). The browser makes an Ajax-style request to the server, which is kept open until the server has new data to send to the browser, which is sent to the browser in a complete response. The browser initiates a new long polling request in order to obtain subsequent events. |
|||
An application using streaming Comet opens a single [[persistent connection]] from the [[Web browser|client browser]] to the server for all Comet [[Event (computing)|events]]. These events are incrementally handled and interpreted on the client side every time the server sends a new event, with neither side closing the connection.<ref name = "WRC">{{cite web | url = http://www.webreference.com/programming/javascript/rg28/ | title = Comet Programming: Using Ajax to Simulate Server Push | access-date = 2010-10-20 | last = Gravelle | first = Rob | publisher = Webreference.com | archive-url = https://web.archive.org/web/20101018055530/http://www.webreference.com/programming/javascript/rg28/ | archive-date = 2010-10-18 | url-status = dead }}</ref> |
|||
Specific |
Specific techniques for accomplishing streaming Comet include the following: |
||
==== |
====Hidden iframe==== |
||
A basic technique for dynamic web application is to use a hidden [[HTML element#Frames|iframe]] HTML element (an ''inline frame'', which allows a website to embed one HTML document inside another). This invisible iframe is sent as a [[Chunked transfer encoding|chunked]] block, which implicitly declares it as infinitely long (sometimes called "forever frame"). As events occur, the iframe is gradually filled with <code>script</code> tags, containing JavaScript to be executed in the browser. Because browsers render HTML pages incrementally, each <code>script</code> tag is executed as it is received. Some browsers require a specific minimum document size before parsing and execution is started, which can be obtained by initially sending 1–2 kB of padding spaces.<ref name="ajaxoreilly">{{cite book |
|||
| last = Holdener III |
|||
| first = Anthony T. |
|||
| title = Ajax: The Definitive Guide |
|||
| publisher = [[O'Reilly Media]] |
|||
|date=January 2008 |
|||
| isbn = 978-0-596-52838-6 |
|||
| chapter = Page Layout with Frames that Aren't |
|||
| page = 320 |
|||
}}</ref> |
|||
One benefit of the iframes method is that it works in every common browser. Two downsides of this technique are the lack of a reliable error handling method, and the impossibility of tracking the state of the request calling process.<ref name="ajaxoreilly"/> |
|||
For the most part, XMLHttpRequest long polling works like any standard use of XHR. The browser makes an asynchronous request of the server, which may wait for data to be available before responding. |
|||
The response can contain encoded data (typically [[XML]] or [[JSON]]) or Javascript to be executed by the client. At the end of the processing of the response, the browser creates and sends another XHR, to await the next event. Thus the browser always keeps a request outstanding with the server, to be answered as each event occurs. |
|||
==== |
====XMLHttpRequest==== |
||
The [[XMLHttpRequest]] (XHR) object, a tool used by Ajax applications for browser–server communication, can also be pressed into service for server–browser Comet messaging by generating a custom data format for an XHR response, and parsing out each event using browser-side JavaScript; relying only on the browser firing the <code>onreadystatechange</code> callback each time it receives new data. |
|||
===Ajax with long polling=== |
|||
{{original research|date=December 2017}} |
|||
None of the above streaming transports work across all modern browsers without negative side-effects. This forces Comet developers to implement several complex streaming transports, switching between them depending on the browser. Consequently, many Comet applications use long polling, which is easier to implement on the browser side, and works, at minimum, in every browser that supports XHR. As the name suggests, long polling requires the client to poll the server for an event (or set of events). The browser makes an Ajax-style request to the server, which is kept open until the server has new data to send to the browser, which is sent to the browser in a complete response. The browser initiates a new long polling request in order to obtain subsequent events. [https://tools.ietf.org/html/rfc6202 IETF RFC 6202 "Known Issues and Best Practices for the Use of Long Polling and Streaming in Bidirectional HTTP"] compares long polling and HTTP streaming. |
|||
Specific technologies for accomplishing long-polling include the following: |
|||
====XMLHttpRequest long polling==== |
|||
For the most part, [[XMLHttpRequest]] long polling works like any standard use of XHR. The browser makes an asynchronous request of the server, which may wait for data to be available before responding. The response can contain encoded data (typically [[XML]] or [[JSON]]) or Javascript to be executed by the client. At the end of the processing of the response, the browser creates and sends another XHR, to await the next event. Thus the browser always keeps a request outstanding with the server, to be answered as each event occurs. |
|||
====Script tag long polling==== |
|||
While any Comet transport can be made to work across [[subdomains]], none of the above transports can be used across different [[second-level domain]]s (SLDs), due to browser security policies designed to prevent [[cross-site scripting]] attacks.<ref name="xss">{{cite book |
While any Comet transport can be made to work across [[subdomains]], none of the above transports can be used across different [[second-level domain]]s (SLDs), due to browser security policies designed to prevent [[cross-site scripting]] attacks.<ref name="xss">{{cite book |
||
|last=Flanagan |
|last=Flanagan |
||
|first=David |
|first=David |
||
|title=JavaScript the Definitive Guide |
|title=JavaScript the Definitive Guide |
||
|url=https://archive.org/details/javascript00libg_297 |
|||
|series=The Definitive Guide |
|||
|url-access=registration |
|||
|date=2006-08-17 |
|date=2006-08-17 |
||
|publisher=[[O'Reilly Media]] |
|publisher=[[O'Reilly Media]] |
||
|isbn=0-596-10199-6 |
|||
|language=English |
|||
|isbn=0596101996 |
|||
|chapter=13.8.4 Cross-Site Scripting |
|chapter=13.8.4 Cross-Site Scripting |
||
|page=[https://archive.org/details/javascript00libg_297/page/n981 994] |
|||
|page=994 |
|||
}}</ref> |
}}</ref> That is, if the main web page is served from one SLD, and the Comet server is located at another SLD (which does not have [[cross-origin resource sharing]] enabled), Comet events cannot be used to modify the HTML and DOM of the main page, using those transports. This problem can be sidestepped by creating a [[proxy server]] in front of one or both sources, making them appear to originate from the same domain. However, this is often undesirable for complexity or performance reasons. |
||
Unlike |
Unlike iframes or XMLHttpRequest objects, <code>script</code> tags can be pointed at any [[Uniform Resource Identifier|URI]], and JavaScript code in the response will be executed in the current HTML document. This creates a potential security risk for both servers involved, though the risk to the data provider (in our case, the Comet server) can be avoided using [[JSONP]]. |
||
A long-polling Comet transport can be created by dynamically creating <code>script</code> elements, and setting their source to the location of the Comet server, which then sends back JavaScript (or JSONP) with some event as its payload. |
A long-polling Comet transport can be created by dynamically creating <code>script</code> elements, and setting their source to the location of the Comet server, which then sends back JavaScript (or JSONP) with some event as its payload. Each time the script request is completed, the browser opens a new one, just as in the XHR long polling case. This method has the advantage of being cross-browser while still allowing cross-domain implementations.<ref name="xss"/> |
||
== |
==Alternatives== |
||
=== Early Java applets === |
|||
The ability to embed [[Java applet]]s into browsers made available richer real-time options.{{When|date=February 2009}} An applet can open a raw [[Transmission Control Protocol|TCP]] socket to the server from which it has loaded. This socket can remain open as long as the browser is at the document hosting the applet. Event notifications can be sent in any format — text or binary — and decoded by the applet. |
|||
=== Early push applications === |
|||
Circa 2000, developers began creating the first push applications using client-side JavaScript inside a frame/iFrame{{Or|date=October 2008}}. [[Pushlets]], a framework created by the [[Netherlands|Dutchman]] Just van den Broecke, were one of the first{{Or|date=October 2008}} open source implementations. Pushlets were based on server-side Java servlets, and a client-side JavaScript library.<ref name="pushlets-javaworld">Just van den Broecke ([[3 January]] [[2007]]). “[http://www.javaworld.com/jw-03-2000/jw-03-pushlet.html Pushlets: Send events from servlets to DHTML client browsers]”. |
|||
JavaWorld. Retrieved [[14 December]] [[2007]].</ref> Bang Networks — a [[Silicon Valley]] start-up backed by [[Netscape]] co-founder [[Marc Andreessen]] — had a lavishly-financed attempt to create a real-time push standard for the entire web<ref>{{cite web |
|||
|url=http://news.cnet.com/2100-1023-255088.html |
|||
|title=Will the "refresh" button become obsolete? |
|||
|last=Borland |
|||
|first=John |
|||
|date=2001-04-01 |
|||
|publisher=[[CNET Networks]] |
|||
|format=html |
|||
|language=English |
|||
|accessdate=2008-07-22 |
|||
}}</ref>. |
|||
=== First Comet applications === |
|||
In March 2006, [[software engineer]] Alex Russell coined the term Comet in a post on his personal blog<ref name="alex_comet">Alex Russell ([[3 March]] [[2006]]). “[http://alex.dojotoolkit.org/?p=545 Comet: Low Latency Data for the Browser]”. Alex Russell’s blog. Retrieved [[29 November]] [[2007]].</ref>. The new term was a play on Ajax ([[Ajax (cleanser)|Ajax]] and [[Comet (cleanser)|Comet]] both being common household cleansers)<ref>{{cite web |
|||
|url=http://www.eweek.com/c/a/Application-Development/Microsoft-Scrubs-Comet-from-AJAX-Tool-Set/ |
|||
|title=Microsoft Scrubs Comet from AJAX Tool Set |
|||
|last=K. Taft |
|||
|first=Darryl |
|||
|date=2006-05-12 |
|||
|format=html |
|||
|publisher=eWEEK.com |
|||
|accessdate=2008-07-21 |
|||
}}</ref>. This [[umbrella term]] for previously existing concepts attracted some enthusiasts, that since then advocate its use in web-related technology conferences and websites.<ref>[http://en.oreilly.com/oscon2008/public/schedule/detail/3048 Orbited: Enabling Comet for the Masses: OSCON 2008 - O'Reilly Conferences, July 21 - 25, 2008, Portland, Oregon<!-- Bot generated title -->]</ref><ref>[http://www.web2journal.com/read/457966.htm Enterprise Comet & Web 2.0 Live Presentation<!-- Bot generated title -->]</ref> |
|||
In 2006, while not really using the term Comet, some applications exposed those techniques to a wider audience: [[Meebo]]’s multi-protocol web-based chat application enables users to connect to [[AOL Instant Messenger|AOL]], [[Yahoo! Messenger|Yahoo]], and [[MSN Messenger|Microsoft]] chat platforms through the browser; Google added web-based chat to [[Gmail]]; [[JotSpot]], a startup since acquired by Google, built Comet-based real-time collaborative document editing; and Comet-based chat is the centerpiece of the event-planning site [[Renkoo]].<ref>Dion Almaer ([[29 September]] [[2005]]). “[http://ajaxian.com/archives/jotspot-live-live-group-note-taking Jotspot Live: Live, group note-taking]” (interview with Abe Fettig). Ajaxian. Retrieved [[15 December]] [[2007]]. <br>Matt Marshall ([[15 December]] [[2006]]). “[http://venturebeat.com/2006/12/15/renkoo-launches-just-in-time-to-schedule-holiday-cocktails/ Renkoo launches event service — in time to schedule holiday cocktails]”. Venture Beat. Retrieved [[15 December]] [[2007]].</ref> New Comet companies and enterprise solutions were created, such as the Java-based [[ICEfaces]] [[JavaServer Faces|JSF]] framework (although they prefer the term "''Ajax Push''"<ref name="ice"/>). Others that had previously used Java-applet based transports switched instead to pure-JavaScript implementations.<ref>Clint Boulton ([[27 December]] [[2005]]). “[http://www.devxnews.com/article.php/3573506/ Startups Board the AJAX Bandwagon]”. DevX News. Retrieved [[18 February]] [[2008]].</ref> |
|||
== Alternatives == |
|||
Browser-native technologies are inherent in the term Comet. Attempts to improve non-polling HTTP communication have come from multiple sides: |
Browser-native technologies are inherent in the term Comet. Attempts to improve non-polling HTTP communication have come from multiple sides: |
||
* The [[HTML 5]] draft specification produced by the [[Web Hypertext Application Technology Working Group]] (WHATWG) specifies so called server-sent events<ref name= |
* The [[HTML 5]] draft specification produced by the [[Web Hypertext Application Technology Working Group]] (WHATWG) specifies so called [[server-sent events]],<ref name="server-sent-events">{{cite web|editor=Ian Hickson |date=2007-10-27 |work=HTML 5 - Call For Comments|title=6.2 Server-sent DOM events|url=http://www.whatwg.org/specs/web-apps/2007-10-26/multipage/section-server-sent-events.html#server-sent-events |publisher=[[WHATWG]]|access-date=2008-10-07}}</ref> which defines a new JavaScript interface <code>EventSource</code> and a new MIME type <code>text/event-stream</code>. [[Server-sent events#Web browsers|All major browsers except Microsoft Internet Explorer]] include this technology. |
||
* The [[HTML 5]] [[WebSocket]] API working draft specifies a method for creating a persistent connection with a server and receiving messages via an <code>onmessage</code> callback.<ref> |
|||
|url=http://labs.opera.com/news/2006/09/01/ |
|||
{{cite web |
|||
|title=Event Streaming to Web Browsers |
|||
|url=http://www.w3.org/TR/websockets/ |
|||
|last=Bersvendsen |
|||
|title=The WebSocket API |
|||
|first=Arve |
|||
|last=Hickson |
|||
|publisher=[[Opera Software]] |
|||
|first=Ian |
|||
|date=2006-09-01 |
|||
|publisher=[[W3C]] |
|||
|accessdate=2009-06-01 |
|||
|date=2009-04-23 |
|||
}}</ref> |
|||
|access-date=2009-07-21 |
|||
* The Bayeux protocol by the [[Dojo Foundation]]. It leaves browser-specific transports in place, and defines a higher-level protocol for communication between browser and server, with the aim of allowing re-use of client-side JavaScript code with multiple Comet servers, and allowing the same Comet server to communicate with multiple client-side JavaScript implementations. Bayeux is based on a publish/subscribe model, so servers supporting Bayeux have publish/subscribe built-in.<ref name="bayeux">{{cite web|author=Alex Russell, et al. |year=2007 |url=http://svn.cometd.org/trunk/bayeux/bayeux.html|title=Bayeux Protocol - Bayeux 1.0draft1.| publisher= Dojo Foundation| accessdate=2007-12-14}}</ref> |
|||
}} |
|||
* The [[BOSH]] protocol by the XMPP standards foundation. It emulates a bidirectional stream between browser and server by using multiple synchronous HTTP connections. |
|||
</ref> |
|||
* The JSONRequest object, proposed by Douglas Crockford, would be an alternative to the XHR object.<ref>{{cite web |
|||
* The Bayeux protocol by the [[Dojo Foundation]]. It leaves browser-specific transports in place, and defines a higher-level protocol for communication between browser and server, with the aim of allowing re-use of [[client-side JavaScript]] code with multiple Comet servers, and allowing the same Comet server to communicate with multiple client-side JavaScript implementations. Bayeux is based on a publish/subscribe model, so servers supporting Bayeux have publish/subscribe built-in.<ref name="bayeux">{{cite web|author=Alex Russell |year=2007 |url=http://svn.cometd.org/trunk/bayeux/bayeux.html|title=Bayeux Protocol - Bayeux 1.0draft1.| publisher= Dojo Foundation| access-date=2007-12-14|display-authors=etal}}</ref> |
|||
* The [[BOSH (protocol)|BOSH]] protocol by the XMPP standards foundation. It emulates a bidirectional stream between the browser and server by using two synchronous HTTP connections. |
|||
* The JSONRequest object, proposed by [[Douglas Crockford]], would be an alternative to the XHR object.<ref>{{cite web |
|||
|url=http://www.json.org/JSONRequest.html |
|url=http://www.json.org/JSONRequest.html |
||
|title = JSONRequest Duplex |
|title = JSONRequest Duplex |
||
Line 186: | Line 202: | ||
|work = An alternative to XMLHttpRequest for long lasting server initiated push of data |
|work = An alternative to XMLHttpRequest for long lasting server initiated push of data |
||
|date = 2006-04-17 |
|date = 2006-04-17 |
||
| |
|access-date = 2008-05-05 |
||
}}</ref> |
}}</ref> |
||
* Use of plugins, such as [[Java applet]]s or the proprietary [[Adobe Flash]] ( |
* Use of plugins, such as [[Java applet]]s or the proprietary [[Adobe Flash]] (using [[Real-Time Messaging Protocol|RTMP]] protocol for data streaming to Flash applications). These have the advantage of working identically across all browsers with the appropriate plugin installed and need not rely on HTTP connections, but the disadvantage of requiring the plugin to be installed |
||
* [[Google]] announced<ref>App, The. (2010-12-02) [http://googleappengine.blogspot.com/2010/12/happy-holidays-from-app-engine-team-140.html Google App Engine Blog: Happy Holidays from the App Engine team - 1.4.0 SDK released]. Googleappengine.blogspot.com. Retrieved on 2014-04-12.</ref> a new Channel API for [[Google App Engine]],<ref>Paul, Ryan. (2010-12-06) [https://arstechnica.com/web/news/2010/12/app-engine-gets-streaming-api-and-longer-background-tasks.ars App Engine gets Streaming API and longer background tasks]. Ars Technica. Retrieved on 2014-04-12.</ref> implementing a Comet-like API with the help of a client JavaScript library on the browser. This API has been deprecated.<ref>{{cite web |url=https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/enwiki/api/channel/package-summary |title=Package com.google.appengine.api.channel |date=2019-11-16 |access-date=2020-04-30 |quote=This API has been deprecated. }}</ref> |
|||
== |
==See also== |
||
*[[Push technology]] |
* [[Push technology]] |
||
*[[Pull technology]] |
* [[Pull technology]] |
||
== |
== Notes == |
||
{{ |
{{notelist}} |
||
==References== |
|||
== External links == |
|||
{{Reflist|2}} |
|||
* [http://cometdaily.com Comet Daily] – a website dedicated to articles on Comet techniques |
|||
* [http://ajaxpatterns.org/HTTP_Streaming HTTP Streaming] at Ajax Patterns |
|||
==External links== |
|||
* {{cite web |title=Comet Daily |url=http://cometdaily.com/ |archive-url=https://web.archive.org/web/20080104091304/http://cometdaily.com/ |archive-date=2008-01-04 |url-status=dead |quote=Comet Daily provides information about Comet techniques. |access-date=2007-11-29 }}* |
|||
{{DEFAULTSORT:Comet (Programming)}} |
|||
[[Category:Ajax (programming)]] |
[[Category:Ajax (programming)]] |
||
[[Category:Buzzwords]] |
|||
[[Category:Web development]] |
|||
[[Category:Web 2.0 neologisms]] |
[[Category:Web 2.0 neologisms]] |
||
[[Category:Web development]] |
|||
[[es:Comet]] |
|||
[[fr:Comet (informatique)]] |
|||
[[hu:Comet]] |
|||
[[ja:Comet]] |
|||
[[mk:Comet]] |
|||
[[pt:Comet (programação)]] |
|||
[[ru:Comet (программирование)]] |
Latest revision as of 06:55, 3 November 2024
Comet is a web application model in which a long-held HTTPS request allows a web server to push data to a browser, without the browser explicitly requesting it.[1][2] Comet is an umbrella term, encompassing multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as JavaScript, rather than on non-default plugins. The Comet approach differs from the original model of the web, in which a browser requests a complete web page at a time.[3]
The use of Comet techniques in web development predates the use of the word Comet as a neologism for the collective techniques. Comet is known by several other names, including Ajax Push,[4][5] Reverse Ajax,[6] Two-way-web,[7] HTTP Streaming,[7] and HTTP server push[8] among others.[9] The term Comet is not an acronym, but was coined by Alex Russell in his 2006 blog post.[10][citation needed]
In recent years, the standardisation and widespread support of WebSocket and Server-sent events has rendered the Comet model obsolete.
History
[edit]Early Java applets
[edit]The ability to embed Java applets into browsers (starting with Netscape Navigator 2.0 in March 1996[11]) made two-way sustained communications possible, using a raw TCP socket[12] to communicate between the browser and the server. This socket can remain open as long as the browser is at the document hosting the applet. Event notifications can be sent in any format – text or binary – and decoded by the applet.
The first browser-to-browser communication framework
[edit]The very first application using browser-to-browser communications was Tango Interactive,[13][failed verification] implemented in 1996–98 at the Northeast Parallel Architectures Center (NPAC) at Syracuse University using DARPA funding. TANGO architecture has been patented by Syracuse University.[14] TANGO framework has been extensively used as a distance education tool.[15] The framework has been commercialized by CollabWorx and used in a dozen or so Command&Control and Training applications in the United States Department of Defense[citation needed].
First Comet applications
[edit]The first set of Comet implementations dates back to 2000,[16][unreliable source?] with the Pushlets, Lightstreamer, and KnowNow projects. Pushlets, a framework created by Just van den Broecke, was one of the first[17] open source implementations. Pushlets were based on server-side Java servlets, and a client-side JavaScript library. Bang Networks – a Silicon Valley start-up backed by Netscape co-founder Marc Andreessen – had a lavishly-financed attempt to create a real-time push standard for the entire web.[18]
In April 2001, Chip Morningstar began developing a Java-based (J2SE) web server which used two HTTP sockets to keep open two communications channels between the custom HTTP server he designed and a client designed by Douglas Crockford; a functioning demo system existed as of June 2001.[citation needed] The server and client used a messaging format that the founders of State Software, Inc. assented to coin as JSON following Crockford's suggestion. The entire system, the client libraries, the messaging format known as JSON and the server, became the State Application Framework, parts of which were sold and used by Sun Microsystems, Amazon.com, EDS and Volkswagen.[citation needed]
In March 2006, software engineer Alex Russell coined the term Comet in a post on his personal blog.[19] The new term was a play on Ajax (Ajax and Comet both being common household cleaners in the USA).[20][21][22]
In 2006, some applications exposed those techniques to a wider audience: Meebo’s multi-protocol web-based chat application enabled users to connect to AOL, Yahoo, and Microsoft chat platforms through the browser; Google added web-based chat to Gmail; JotSpot, a startup since acquired by Google, built Comet-based real-time collaborative document editing.[23] New Comet variants were created, such as the Java-based ICEfaces JSF framework (although they prefer the term "Ajax Push"[5]). Others that had previously used Java-applet based transports switched instead to pure-JavaScript implementations.[24]
Implementations
[edit]Comet applications attempt to eliminate the limitations of the page-by-page web model and traditional polling by offering two-way sustained interaction, using a persistent or long-lasting HTTP connection between the server and the client. Since browsers and proxies are not designed with server events in mind, several techniques to achieve this have been developed, each with different benefits and drawbacks. The biggest hurdle is the HTTP 1.1 specification, which states "this specification... encourages clients to be conservative when opening multiple connections".[25] Therefore, holding one connection open for real-time events has a negative impact on browser usability: the browser may be blocked from sending a new request while waiting for the results of a previous request, e.g., a series of images. This can be worked around by creating a distinct hostname for real-time information, which is an alias for the same physical server. This strategy is an application of domain sharding.
Specific methods of implementing Comet fall into two major categories: streaming and long polling.
Streaming
[edit]An application using streaming Comet opens a single persistent connection from the client browser to the server for all Comet events. These events are incrementally handled and interpreted on the client side every time the server sends a new event, with neither side closing the connection.[3]
Specific techniques for accomplishing streaming Comet include the following:
Hidden iframe
[edit]A basic technique for dynamic web application is to use a hidden iframe HTML element (an inline frame, which allows a website to embed one HTML document inside another). This invisible iframe is sent as a chunked block, which implicitly declares it as infinitely long (sometimes called "forever frame"). As events occur, the iframe is gradually filled with script
tags, containing JavaScript to be executed in the browser. Because browsers render HTML pages incrementally, each script
tag is executed as it is received. Some browsers require a specific minimum document size before parsing and execution is started, which can be obtained by initially sending 1–2 kB of padding spaces.[26]
One benefit of the iframes method is that it works in every common browser. Two downsides of this technique are the lack of a reliable error handling method, and the impossibility of tracking the state of the request calling process.[26]
XMLHttpRequest
[edit]The XMLHttpRequest (XHR) object, a tool used by Ajax applications for browser–server communication, can also be pressed into service for server–browser Comet messaging by generating a custom data format for an XHR response, and parsing out each event using browser-side JavaScript; relying only on the browser firing the onreadystatechange
callback each time it receives new data.
Ajax with long polling
[edit]This article possibly contains original research. (December 2017) |
None of the above streaming transports work across all modern browsers without negative side-effects. This forces Comet developers to implement several complex streaming transports, switching between them depending on the browser. Consequently, many Comet applications use long polling, which is easier to implement on the browser side, and works, at minimum, in every browser that supports XHR. As the name suggests, long polling requires the client to poll the server for an event (or set of events). The browser makes an Ajax-style request to the server, which is kept open until the server has new data to send to the browser, which is sent to the browser in a complete response. The browser initiates a new long polling request in order to obtain subsequent events. IETF RFC 6202 "Known Issues and Best Practices for the Use of Long Polling and Streaming in Bidirectional HTTP" compares long polling and HTTP streaming. Specific technologies for accomplishing long-polling include the following:
XMLHttpRequest long polling
[edit]For the most part, XMLHttpRequest long polling works like any standard use of XHR. The browser makes an asynchronous request of the server, which may wait for data to be available before responding. The response can contain encoded data (typically XML or JSON) or Javascript to be executed by the client. At the end of the processing of the response, the browser creates and sends another XHR, to await the next event. Thus the browser always keeps a request outstanding with the server, to be answered as each event occurs.
Script tag long polling
[edit]While any Comet transport can be made to work across subdomains, none of the above transports can be used across different second-level domains (SLDs), due to browser security policies designed to prevent cross-site scripting attacks.[27] That is, if the main web page is served from one SLD, and the Comet server is located at another SLD (which does not have cross-origin resource sharing enabled), Comet events cannot be used to modify the HTML and DOM of the main page, using those transports. This problem can be sidestepped by creating a proxy server in front of one or both sources, making them appear to originate from the same domain. However, this is often undesirable for complexity or performance reasons.
Unlike iframes or XMLHttpRequest objects, script
tags can be pointed at any URI, and JavaScript code in the response will be executed in the current HTML document. This creates a potential security risk for both servers involved, though the risk to the data provider (in our case, the Comet server) can be avoided using JSONP.
A long-polling Comet transport can be created by dynamically creating script
elements, and setting their source to the location of the Comet server, which then sends back JavaScript (or JSONP) with some event as its payload. Each time the script request is completed, the browser opens a new one, just as in the XHR long polling case. This method has the advantage of being cross-browser while still allowing cross-domain implementations.[27]
Alternatives
[edit]Browser-native technologies are inherent in the term Comet. Attempts to improve non-polling HTTP communication have come from multiple sides:
- The HTML 5 draft specification produced by the Web Hypertext Application Technology Working Group (WHATWG) specifies so called server-sent events,[28] which defines a new JavaScript interface
EventSource
and a new MIME typetext/event-stream
. All major browsers except Microsoft Internet Explorer include this technology. - The HTML 5 WebSocket API working draft specifies a method for creating a persistent connection with a server and receiving messages via an
onmessage
callback.[29] - The Bayeux protocol by the Dojo Foundation. It leaves browser-specific transports in place, and defines a higher-level protocol for communication between browser and server, with the aim of allowing re-use of client-side JavaScript code with multiple Comet servers, and allowing the same Comet server to communicate with multiple client-side JavaScript implementations. Bayeux is based on a publish/subscribe model, so servers supporting Bayeux have publish/subscribe built-in.[30]
- The BOSH protocol by the XMPP standards foundation. It emulates a bidirectional stream between the browser and server by using two synchronous HTTP connections.
- The JSONRequest object, proposed by Douglas Crockford, would be an alternative to the XHR object.[31]
- Use of plugins, such as Java applets or the proprietary Adobe Flash (using RTMP protocol for data streaming to Flash applications). These have the advantage of working identically across all browsers with the appropriate plugin installed and need not rely on HTTP connections, but the disadvantage of requiring the plugin to be installed
- Google announced[32] a new Channel API for Google App Engine,[33] implementing a Comet-like API with the help of a client JavaScript library on the browser. This API has been deprecated.[34]
See also
[edit]Notes
[edit]References
[edit]- ^ Krill, Paul (September 24, 2007). "AJAX alliance recognizes mashups". InfoWorld. Retrieved 2010-10-20.
- ^ Crane, Dave; McCarthy, Phil (October 13, 2008). Comet and Reverse Ajax: The Next-Generation Ajax 2.0. Apress. ISBN 978-1-59059-998-3.
- ^ a b Gravelle, Rob. "Comet Programming: Using Ajax to Simulate Server Push". Webreference.com. Archived from the original on 2010-10-18. Retrieved 2010-10-20.
- ^ Egloff, Andreas (2007-05-05). Ajax Push (a.k.a. Comet) with Java Business Integration (JBI) (Speech). JavaOne 2007, San Francisco, California: Sun Microsystems, Inc. Retrieved 2008-06-10.
{{cite speech}}
: CS1 maint: location (link) - ^ a b "Ajax Push". ICEfaces.org. Retrieved 2014-10-23.
- ^ Crane, Dave; McCarthy, Phil (July 2008). Comet and Reverse Ajax: The Next Generation Ajax 2.0. Apress. ISBN 978-1-59059-998-3.
- ^ a b Mahemoff, Michael (June 2006). "Web Remoting". Ajax Design Patterns. O'Reilly Media. pp. 19, 85. ISBN 0-596-10180-5.
- ^ Double, Chris (2005-11-05). "More on Ajax and server push". Different ways of doing server push. Retrieved 2008-05-05.
- ^ Nesbitt, Bryce (2005-11-01). "The Slow Load Technique/Reverse AJAX". Simulating Server Push in a Standard Web Browser. Archived from the original on 2006-02-08. Retrieved 2008-05-06.
- ^ Russell, Alex (2006-03-04). "Comet: Low Latency Data for the Browser". Retrieved 2014-11-02.
- ^ "Netscape.com". Archived from the original on November 15, 1996. Retrieved 2017-08-16.
{{cite web}}
: CS1 maint: bot: original URL status unknown (link) - ^ "java.net.Socket (Java 2 Platform SE v1.4.2)" Archived May 19, 2009, at the Wayback Machine
- ^ Beca, Lukasz (1997). "TANGO - a Collaborative Environment for the World-Wide Web". Syracuse University SURFACE. Northeast Parallel Architecture Center, College of Engineering and Computer Science. Retrieved 27 February 2016.
- ^ Podgorny, Marek; Beca, Lukasz; Cheng, Gang; Fox, Geoffrey C.; Jurga, Tomasz; Olszewski, Konrad; Sokolowski, Piotr; Walczak, Krzysztof; PL (June 20, 2000), United States Patent: 6078948 - Platform-independent collaboration backbone and framework for forming virtual communities having virtual rooms with collaborative sessions, archived from the original on 2017-05-09, retrieved 2016-02-27
- ^ Baer, Troy (1999). "Experiences with Using TANGO Interactive in a Distributed Workshop" (PDF). CEWES Major Shared Resource Center. CEWES MSRC/PET TR/99-21. Archived from the original (PDF) on 8 March 2021. Retrieved 27 February 2016.
- ^ "CometDaily: Comet and Push Technology". Archived from the original on 2007-11-13. Retrieved 2007-12-15.
- ^ Just van den Broecke (1 March 2000). “Pushlets: Send events from servlets to DHTML client browsers Archived 2014-08-04 at the Wayback Machine”. JavaWorld. Retrieved 1 August 2014.
- ^ Borland, John (2001-04-01). "Will the "refresh" button become obsolete?". CNET Networks. Retrieved 2008-07-22.
- ^ Alex Russell (3 March 2006). “Comet: Low Latency Data for the Browser Archived 2008-08-12 at the Wayback Machine”. Alex Russell’s blog. Retrieved 29 November 2007.
- ^ K. Taft, Darryl (2006-05-12). "Microsoft Scrubs Comet from AJAX Tool Set". eWEEK.com. Retrieved 2008-07-21.
- ^ Orbited: Enabling Comet for the Masses: OSCON 2008 - O'Reilly Conferences, July 21 - 25, 2008, Portland, Oregon
- ^ Enterprise Comet & Web 2.0 Live Presentation Archived 2008-05-20 at the Wayback Machine
- ^ Dion Almaer (29 September 2005). “Jotspot Live: Live, group note-taking” (interview with Abe Fettig). Ajaxian. Retrieved 15 December 2007.
Matt Marshall (15 December 2006). “Renkoo launches event service — in time to schedule holiday cocktails”. Venture Beat. Retrieved 15 December 2007. - ^ Clint Boulton (27 December 2005). “Startups Board the AJAX Bandwagon”. DevX News. Retrieved 18 February 2008.
- ^ Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing, section 6.4. IETF. Retrieved 2014-07-29
- ^ a b Holdener III, Anthony T. (January 2008). "Page Layout with Frames that Aren't". Ajax: The Definitive Guide. O'Reilly Media. p. 320. ISBN 978-0-596-52838-6.
- ^ a b Flanagan, David (2006-08-17). "13.8.4 Cross-Site Scripting". JavaScript the Definitive Guide. O'Reilly Media. p. 994. ISBN 0-596-10199-6.
- ^ Ian Hickson, ed. (2007-10-27). "6.2 Server-sent DOM events". HTML 5 - Call For Comments. WHATWG. Retrieved 2008-10-07.
- ^ Hickson, Ian (2009-04-23). "The WebSocket API". W3C. Retrieved 2009-07-21.
- ^ Alex Russell; et al. (2007). "Bayeux Protocol - Bayeux 1.0draft1". Dojo Foundation. Retrieved 2007-12-14.
- ^ Crockford, Douglas (2006-04-17). "JSONRequest Duplex". An alternative to XMLHttpRequest for long lasting server initiated push of data. Retrieved 2008-05-05.
- ^ App, The. (2010-12-02) Google App Engine Blog: Happy Holidays from the App Engine team - 1.4.0 SDK released. Googleappengine.blogspot.com. Retrieved on 2014-04-12.
- ^ Paul, Ryan. (2010-12-06) App Engine gets Streaming API and longer background tasks. Ars Technica. Retrieved on 2014-04-12.
- ^ "Package com.google.appengine.api.channel". 2019-11-16. Retrieved 2020-04-30.
This API has been deprecated.
External links
[edit]- "Comet Daily". Archived from the original on 2008-01-04. Retrieved 2007-11-29.
Comet Daily provides information about Comet techniques.
*