Comet (programming): Difference between revisions

Content deleted Content added
Bender the Bot (talk | contribs)
m Alternatives: HTTP to HTTPS for Blogspot
 
(38 intermediate revisions by 26 users not shown)
Line 1:
{{short description|Web application model}}
'''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 | accessdateaccess-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#How the Web worksFunction|original model of the web]], in which a browser requests a complete web page at a time.<ref name = "WRC" />
 
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
Line 10 ⟶ 11:
| ___location = [[JavaOne]] 2007, [[San Francisco, California]]
| url = http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-8434&yr=2007&track=7
| accessdateaccess-date = 2008-06-10
}}</ref><ref name="ice">{{cite web
|url=http://www.icesoft.org/java/projects/ICEfaces/ajax-push.jsf
|title=Ajax Push
|publisher=ICEfaces.org
| accessdateaccess-date = 2014-10-23
}}</ref>
''Reverse Ajax'',<ref>{{cite book
Line 23 ⟶ 24:
|author2=McCarthy, Phil
|publisher = Apress
|isbn = 978-1-59059-998-53
|date=July 2008
}}</ref> ''Two-way-web'',<ref name="ajax-dp-oreilly"/> ''HTTP Streaming'',<ref name="ajax-dp-oreilly">{{cite book
|title=Ajax Design Patterns
|first=Michael
|last= Mahemoff
|publisher=[[O'Reilly Media]]
|date=June 2006
|isbn=0-596-10180-5
|pages=[https://archive.org/details/ajaxdesignpatter00mahe/page/19 19; 85]
|pages=19; 85
|chapter=Web Remoting
|chapter-url-access=registration
|chapter-url=https://archive.org/details/ajaxdesignpatter00mahe/page/19
}}</ref> and
''[[HTTP push|HTTP server push]]''<ref>{{cite web
Line 42 ⟶ 45:
|last = Double
|date = 2005-11-05
|accessdateaccess-date = 2008-05-05
}}
</ref>
Line 52 ⟶ 55:
|last = Nesbitt
|date = 2005-11-01
|accessdateaccess-date = 2008-05-06
|deadurlurl-status = yesdead
|archiveurlarchive-url = https://web.archive.org/web/20060208041559/http://www.obviously.com/tech_tips/slow_load_technique
|archivedatearchive-date = 2006-02-08
|df =
}}
</ref> The term ''Comet'' is not an acronym, but was coined by Alex Russell in his 2006 [[blog]] post ''Comet: Low Latency Data for the Browser''.<ref>{{cite web
|url = http://infrequently.org/2006/03/comet-low-latency-data-for-the-browser/
|title = Comet: Low Latency Data for the Browser
Line 64 ⟶ 66:
|last = Russell
|date = 2006-03-04
|accessdateaccess-date = 2014-11-02
}}</ref>{{citation needed|date=June 2023}}
}}
 
</ref>
In recent years{{When|date=January 2025}}, the standardisation and widespread support of [[WebSocket]] and [[Server-sent events]] has rendered the Comet model obsolete.
 
==History==
 
===Early Java applets===
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 |accessdateaccess-date=2017-08-16 |deadurlurl-status=bot: unknown |archiveurlarchive-url=https://web.archive.org/web/19961115203505/http://www27.netscape.com/comprod/products/navigator/version_2.0/index.html |archivedatearchive-date=November 15, 1996 |df= }}</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/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/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===
Line 83 ⟶ 86:
| 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|lastlast1 = Podgorny|firstfirst1 = 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|accessdateaccess-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
Line 92 ⟶ 95:
| publisher = CEWES MSRC/PET TR/99-21
| access-date = 27 February 2016
| archive-date = 8 March 2021
}}</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{{fact|date=December 2017}}.
| 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{{factcitation needed|date=December 2017}}.
 
===First Comet applications===
The first set of Comet implementations datedates 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
|url=http://news.cnet.com/2100-1023-255088.html
|title=Will the "refresh" button become obsolete?
Line 102 ⟶ 108:
|date=2001-04-01
|publisher=[[CNET Networks]]
|accessdateaccess-date=2008-07-22
}}</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.<ref>{{citecitation web|url=http://habitatchronicles.com/2009/09/elko-ii-against-statelessness-or-everything-old-is-new-again/|title=Elko II: Against Statelessness (or, Everything Old Is New Again)|first=Chip|last=Morningstar|date={{date|2009-09-06|dmy}}|website=Habitat Chronicles}}</ref>{{self published inlineneeded|date=DecemberFebruary 20172020}} 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.<ref>{{cite web|url=http://habitatchronicles.com/2009/09/elko-i-the-life-death-life-death-life-death-and-resurrection-of-the-elko-session-sever/|title=Elko I: The Life, Death, Life, Death, Life, Death, and Resurrection of The Elko Session Server|first=Chip|last=Morningstar|date={{date|2009-09-05|dmy}}|website=Habitat Chronicles}}</ref>{{self publishedcitation inlineneeded|date=DecemberFebruary 20172020}}
 
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
Line 114 ⟶ 120:
|date=2006-05-12
|publisher=eWEEK.com
|accessdateaccess-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>
 
Line 120 ⟶ 126:
 
==Implementations==
Comet applications attempt to eliminate the limitations of the [[World Wide Web#How the Web worksFunction|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]].
 
===Streaming===
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 | accessdateaccess-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 | dead-url-status = yesdead }}</ref>
 
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.
Line 136 ⟶ 142:
| publisher = [[O'Reilly Media]]
|date=January 2008
| isbn = 978-0-596-52838-86
| chapter = Page Layout with Frames that Aren't
| page = 320
Line 148 ⟶ 154:
===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:
 
Line 159 ⟶ 165:
|first=David
|title=JavaScript the Definitive Guide
|url=https://archive.org/details/javascript00libg_297
|series=The Definitive Guide
|url-access=registration
|date=2006-08-17
|publisher=[[O'Reilly Media]]
|isbn=0-596-10199-6
|chapter=13.8.4 Cross-Site Scripting
|page=[https://archive.org/details/javascript00libg_297/page/n981 994]
|page=994
}}</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.
 
Line 174 ⟶ 181:
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='"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]]|accessdateaccess-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 Edge]] 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>
{{cite web
|url=http://www.w3.org/TR/websockets/
Line 181 ⟶ 188:
|last=Hickson
|first=Ian
|publisher=[[w3cW3C]]
|date=2009-04-23
|accessdateaccess-date=2009-07-21
}}
</ref>
* 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| accessdateaccess-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
Line 195 ⟶ 202:
|work = An alternative to XMLHttpRequest for long lasting server initiated push of data
|date = 2006-04-17
|accessdateaccess-date = 2008-05-05
}}</ref>
* 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) [httphttps://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. ItThis couldAPI behas laterbeen replaceddeprecated.<ref>{{cite byweb [[HTML5]]|url=https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/channel/package-summary [[WebSocket]],|title=Package howevercom.google.appengine.api.channel |date=2019-11-16 |access-date=2020-04-30 |quote=This API has been deprecated. }}</ref>
 
==See also==
* [[Push technology]]
* [[Pull technology]]
 
== Notes ==
{{notelist}}
 
==References==
Line 208 ⟶ 218:
 
==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 ainformation website dedicated to articles onabout Comet techniques. |access-date=2007-11-29 }}*
* [https://web.archive.org/web/20080330033520/http://cometdaily.com/maturity.html Comparison of several comet server implementations]
 
{{DEFAULTSORT:Comet (Programming)}}