`
bethel
  • 浏览: 23191 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
社区版块
存档分类
最新评论

Comet - Wikipedia(英文)

    博客分类:
  • Wiki
阅读更多

转自 " http://en.wikipedia.org/wiki/Comet_(programming) "

 

Comet

 

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

In theory, the Comet approach differs from the 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 with 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 , [1] [2] Reverse Ajax , [3] Two-way-web , [4] HTTP Streaming , [4] and HTTP server push [5] among others. [6]

 

 

Contents

[ hide ]

[ edit ] Implementations

 

 

This section needs attention from an expert on the subject . See the talk page for details. WikiProject Technology or the Technology Portal may be able to help recruit an expert. (October 2008)

Comet is an umbrella term for technologies that attempt to eliminate both the limitations of the page-by-page web model and traditional 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 . [7] 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.

Specific methods of implementing Comet fall into two major categories: streaming and long polling.

[ edit ] Streaming

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.

[ edit ] Hidden IFrame

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. [8]

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 . [8]

[ edit ] XMLHttpRequest

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.

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 multipart HTTP response (see History section, below), using the content type multipart/x-mixed-replace . Since 2004, Gecko -based browsers such as Firefox accept multipart responses to XHR, which can therefore be used as a streaming Comet transport . [9] On the server side, each message is encoded as a separate portion of the multipart response, and on the client, the callback function provided to the XHR onreadystatechange 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. [10]

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 onreadystatechange callback each time it receives new data.

[ edit ] Ajax with long polling

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.

Specific technologies for accomplishing long-polling include the following.

[ edit ] 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.

[ edit ] 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 domains (SLDs), due to browser security policies designed to prevent cross-site scripting attacks. [11] That is, if the main web page is served from one SLD, and the Comet server is located at another SLD, Comet events cannot be used to modify the HTML and DOM of the main page, using those transports. This problem can be side-stepped 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. [11]

[ edit ] History

[ edit ] Early Java applets

The ability to embed Java applets into browsers (starting with Netscape 2.0 in March 1996 [12] ) made real-time communications possible, using a raw TCP socket [13] 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.

[ edit ] First Comet applications

In March 2006, software engineer Alex Russell coined the term Comet in a post on his personal blog[14] . The new term was a play on Ajax ( Ajax and Comet both being household cleaners, common in the USA)[15] . This umbrella term for previously existing concepts attracted some enthusiasts, that since then advocate its use in web-related technology conferences and websites. [16] [17]

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 , 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; and Comet-based chat is the centerpiece of the event-planning site Renkoo . [18] New Comet companies and enterprise solutions were created, such as the Java-based ICEfaces JSF framework (although they prefer the term "Ajax Push " [2] ). Others that had previously used Java-applet based transports switched instead to pure-JavaScript implementations . [19]

[ edit ] Alternatives

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 [20] , it offers a new HTML element, event-source and a new data format called DOM event stream. Experimental implementation of this feature was introduced in Opera 9. [21]
  • The HTML 5 Web Sockets API working draft specifies a method for creating a persistent connection with a server and receiving messages via an onmessage callback. [22]
  • 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 . [23]
  • The BOSH protocol by the XMPP standards foundation, usabe elsewhere. It emulates a bidirectional stream between browser and server by using two synchronous HTTP connections.
  • The JSON Request object, proposed by Douglas Crockford, would be an alternative to the XHR object . [24]
  • Use of plugins, such as Java applets or the proprietary Adobe Flash (Java BlazeDS is a server plugin which streams events 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

[ edit ] See also

[ edit ] References

  1. ^ Egloff, Andreas. "Ajax Push (a.k.a. Comet) with Java Business Integration (JBI)" JavaOne 2007, San Francisco, California (2007-05-05). Retrieved on 2008-06-10.
  2. ^ a b "Ajax Push" (in English) (html). ICEfaces.org. http://www.icefaces.org/main/product/ajaxpush.iface . Retrieved 2008-07-21. 
  3. ^ Crane, Dave; McCarthy, Phil (July 2008) (in English). Comet and Reverse Ajax: The Next Generation Ajax 2.0 . Apress. ISBN   1590599985 . 
  4. ^ a b Mahemoff, Michael (June 2006). "Web Remoting" (in English). Ajax Design Patterns . O'Reilly Media . pp. 19; 85. ISBN   0596101805 . 
  5. ^ Double, Chris (2005-11-05). "More on Ajax and server push" . Different ways of doing server push . http://www.bluishcoder.co.nz/2005/11/more-on-ajax-and-server-push.html . Retrieved 2008-05-05. 
  6. ^ Nesbitt, Bryce (2005-11-01). "The Slow Load Technique/Reverse AJAX" . Simulating Server Push in a Standard Web Browser . http://www.obviously.com/tech_tips/slow_load_technique . Retrieved 2008-05-05. 
  7. ^ HTTP 1.1 specification, section 8.1.4 . W3C. Retrieved 30 November 2007

 

分享到:
评论

相关推荐

    comet-iframe.rar

    将Comet与IFrame结合,可以在IFrame中利用Comet技术实现数据的实时更新,这对于构建实时聊天、股票报价、在线游戏等应用非常有用。 PHPComet是一款基于PHP的Comet服务器,它提供了一种简单的方法来实现PHP环境下的...

    comet-ajax

    comet-ajax聊天comet-ajax聊天comet-ajax聊天comet-ajax聊天comet-ajax聊天comet-ajax聊天comet-ajax聊天comet-ajax聊天comet-ajax聊天

    comet-atomic-2020

    (Comet-)ATOMIC 2020:关于符号和神经常识知识图 纸 耶拿·黄(Jena D. Hwang),钱德拉(Chandra Bhagavatula),罗南·勒布拉斯(Ronan Le Bras),杰夫·达(Jeff Da),坂口圭介(Keisuke Sakaguchi),安托万...

    gwt-comet-jar包+实例+source.jar包,

    里面东西很多,都是关于GWT-COMET的内容,实现gwt的服务器推技术,包括gwt-comet-examples-1.2.3:google官网上的Test实例;gwt-comet-1.2.3.jar:jar包,gwt-example:聊天实例源代码(.java的),gwt-event-source...

    Python库 | unbabel-comet-0.0.1.tar.gz

    在本文中,我们将深入探讨名为"unbabel-comet-0.0.1"的Python库,该库被封装在一个名为"unbabel-comet-0.0.1.tar.gz"的压缩文件中。 "unbabel-comet-0.0.1.tar.gz"是一个典型的源代码打包文件,它采用了tar格式用于...

    atmosphere-flick-comet-0.2-m1-sources.jar

    atmosphere-flick-comet-0.2-m1-sources.jar

    atmosphere-flick-comet-0.3.1-sources.jar

    atmosphere-flick-comet-0.3.1-sources.jar

    atmosphere-flick-comet-0.5.1-sources.jar

    atmosphere-flick-comet-0.5.1-sources.jar

    atmosphere-flick-comet-0.4-sources.jar

    atmosphere-flick-comet-0.4-sources.jar

    atmosphere-flick-comet-0.3-sources.jar

    atmosphere-flick-comet-0.3-sources.jar

    atmosphere-flick-comet-0.2-sources.jar

    atmosphere-flick-comet-0.2-sources.jar

    atmosphere-flick-comet-0.1-sources.jar

    atmosphere-flick-comet-0.1-sources.jar

    科密点钞机升级操作指引教程

    科密点钞机升级操作指引教程,升级识别2015版人民币 WJD-Comet-A30 WJD-Comet-B329 WJD-Comet-C518 WJD-Comet-D629 WJD-Comet-KM2800 WJD-Comet-KM6800

    comet-for-mlflow:Comet-For-MLFlow扩展

    Comet-For-MLFlow扩展 Comet-For-MLFlow扩展是一个CLI,可将MLFlow实验运行映射到Comet实验。 此扩展程序使您可以在Comet.ml UI中查看现有实验,该UI提供了对实验结果的经过身份验证的访问权限,大大提高了大批量...

    comet-jquery

    【comet-jquery】是一种基于jQuery的实时通信技术,它利用了Comet技术来实现服务器向客户端推送数据的功能。在Web开发中,传统的HTTP协议是请求-响应模式,即客户端发起请求,服务器返回数据,而Comet技术打破了这种...

    科密票据打印机官方驱动程序 COMET-CM-30 官方版(32位/64位)

    科密票据打印机官方驱动程序 COMET-CM-30是CM-30票据打印机的官方驱动,使用这款驱动能完美驱程COMET-CM-30的票据打印机,有需要的用户可以下载驱动程序安装。小编已经把win32位和win64位的驱动都打包在压缩包里,请...

    科密票据打印机官方驱动程序 COMET-CK-300K 官方版(32位/64位)

    科密票据打印机官方驱动程序 COMET-CK-300K是CK-300K打印机的专用驱动程序,能完美驱程COMET-CK-300K的票据打印机,有需要的用户可以下载驱动程序安装。小编提供了32位和64位的驱动,请用户根据自身系统选择对应的...

    Python库 | comet_ml-2.0.12.tar.gz

    《Python库Comet_ml-2.0.12:跟踪、优化与实验管理》 在IT行业中,Python作为一门强大的开发语言,拥有丰富的库支持,其中Comet_ml就是一款专为机器学习和深度学习项目提供实验跟踪、模型优化以及协作功能的库。...

    comet-php with chatroom demo

    Comet是一种Web实时通信技术,它允许服务器向客户端推送数据,而不仅仅是响应客户端的请求,从而实现了双向通信。 【描述】提到的是一个用C++编写的Comet服务器,该服务器目前提供PHP接口,简化了Comet应用程序的...

    comet-java-sdk:彗星Java SDK

    Comet-Java-SDK该项目仍在开发中。使用Comet Java SDK: 最新的发行版本可在Maven Central中获得: : q 将相应的依赖项添加到pom.xml。 例如: <dependencies> <dependency> <groupId>ml.comet</groupId> ...

Global site tag (gtag.js) - Google Analytics