`
sillycat
  • 浏览: 2552492 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Comet-Jetty(1)CometD Design and Go through document

    博客分类:
  • UI
 
阅读更多
Comet-Jetty(1)CometD Design and Go through document

First of all, I tried jetty6.1.3, chat demo. I have demoed that before. But I do not think it is a good way to solve my problem on hand.

So I try to download the latest cometd2.x project and read the document.

1. Prepare the project
>git clone https://github.com/cometd/cometd.git

build the whole project at the root path
>mvn clean install

I think there are many parts useful to me.
1.1 full chat applications with jquery
1.2 examples of extensions such as message acknowledgement, reload, timesync and timestamp.
1.3 an example of how to echo private message to a particular client only

running the demos with maven.
>cd cometd-demo
>mvn jetty:deploy-war

Then I visit the URL http://localhost:8080 to take a look at the demo.

2. Primer
2.2.1 Setting Up the Project in Maven Way
CometD libraries using maven uses the maven archetype, which create the skeleton of the project.
>cd D:\work\cometd
>mvn archetype:generate -DarchetypeCatalog=http://cometd.org

I choose 5 to have a try here:
5: http://cometd.org -> org.cometd.archetypes:cometd-archetype-spring-jquery-jetty7 (2.4.3 - CometD
archetype for creating a server-side event-driven web application)

Confirm properties configuration:
groupId: com.sillycat
artifactId: easycometd
version: 1.0
package: com.sillycat.easycometd
cometdVersion: 2.4.3
jettyVersion: 7.6.4.v20120524
slf4jVersion: 1.6.4
springVersion: 3.1.1.RELEASE

I copy the directory to my working directory d:/work/easy/easycometd.
>cd d:/work/easy/easycometd
>mvn eclipse:eclipse
I can import this project to eclipse. I delete the parent configuration in pom
<parent>
    <artifactId>cometd-project</artifactId>
    <groupId>org.cometd</groupId>
    <version>2.5.0-SNAPSHOT</version>
</parent>

And take a look at the demo.
>mvn install jetty:run

We can visit this URL http://localhost:8080/easycometd/, but there is not much information. I will try more on this demo after I read documents.

3. Concept & Architecture
The CometD Project uses the Bayeux protocol to exchange the information between the client and the server.
The unit of information exchanged is a Bayeux message formatted in JSON.

All messages the client and server exchange have a channel field. The channel field provides the characterization of messages in classes. The channel is a central concept in CometD: publishers publish messages to channels, and subscribers subscribe to channels to receive messages. This is strongly reflected in the CometD APIs.

3.1.1.Channel Definitions
A channel that starts with /meta/ is a meta channel, a channel that starts with /service/ is a service channel, and all other channels are broadcast channels.

3.1.1.1 Meta Channels
CometD implementation creates meta channels, application can not. Provide information about protocol.

3.1.1.2. Service Channels
Applications create service channels for request/response style of communication.

3.1.1.3. Broadcast Channels
Applications also create broadcast channels. One sender wants to broadcast information to multiple recipients.

3.1.1.4. Use of Wildcards in Channels

3.3.1 Sessions
Client Sessions
org.cometd.bayeux.client.ClientSession
org.cometd.bayeux.client.BayeuxClient
Server Sessions
org.cometd.bayeux.server.ServerSession

they are the counterpart of client sessions. When a client creates a client session, it is not initially associated with a correspondent server session. Only when a client session establishes the Bayeux communication with the server does the server create its correspondent server session, as well as the link between the two half-objects.

Local Sessions
org.cometd.bayeux.server.LocalSession

Local sessions can be thought of as clients living in the server. They do not represent a remote client, but instead a server-side client.

3.3.4 Message Processing
3.3.5. Application Interaction

4.1. Configuring and Initializing
in application.js, we can see the configuring:
var cometURL = location.protocol + "//" + location.host + config.contextPath + "/cometd";
       cometd.configure({
           url: cometURL,
           logLevel: 'debug'
       });
After we call cometd.handshake(); The client will connect to the server.
The call to handshake() (or to init()) initiates the Bayeux communication with the Bayeux server.

4.2. Handshaking
The client and the server negotiate the type of transport to use.
Once the transport negotiates successfully, the server informs the client with the detailed timings of the requests.

4.3.4. Subscribers and Listeners
addListener() ----> removeListener()
subscribe()    ----> unsubscribe()

addListener()
Must be used to listen to meta channel messages
May be used to listen to service channel messages
Should not be used to listen broadcast channel messages(use subscribe() instead)
Is synchronous
Does not involve any communication with the Bayeux server, and as such can be called before calling handshake().

subscribe()
Must not be used to listen to meta channels messages
May be used to listen to service channel message(but recommend, prefer to use addListener())
Should be used to listen to broadcast channel messages
Involves a communication with the Bayeux server and as such cannot be called before calling handshake().
Is asynchronous:

4.3.6. Wildcard Subscriptions
cometd.subscribe("/chatrooms/*", function(message) { ... });

4.3.7. Meta Channel List
/meta/handshake
/meta/connect
/meta/disconnect
/meta/subscribe
/meta/unsubscribe
/meta/publish
/meta/unsuccessful

4.4. Publishing
publish data onto a certain channel
cometd.publish('/mychannel',{ mydata: { foo: 'bar' } }};

It is asynchronous: it returns immediately, well before the Bayeux server has received the message.

4.7. JavaScript Transports
4.7.1. The long-polling Transport
The long-polling transport is the default transport if the browser and the server do not support WebSockets. The data is sent to the server by means of a POST request with Content-Type application/json via a plain XMLHttpRequest call.
This transport is used when the communication with the Bayeux server happens on the same domain.

Client will ask the Server for reply, if no data, Client will wait to timeout, if data, Client will receive and make another request.

4.7.2. The callback-polling Transport
The callback-polling transport is used when the communication with the Bayeux server happens on a different domain.
To overcome XMLHttpRequest restrictions, this transport uses the JSONP script injection, which injects a <script> element whose src attribute points to the Bayeux server.

4.7.3. The websocket Transport
4.7.4. Unregistering Transports
var cometd = dojox.cometd; // Dojo style
var cometd = $.cometd; // jQuery style
cometd.unregisterTransport('websocket');

The purpose is to disable certain transports that might be unreliable.


references:
http://timyang.net/category/architecture/
http://sillycat.iteye.com/blog/563598

http://wiki.eclipse.org/Jetty/
https://github.com/eclipse/jetty.project
http://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project.git

http://ftp.jaist.ac.jp/pub/eclipse/jetty/index.html

http://oss.sonatype.org/content/groups/jetty/

http://cometd.org/
http://haidii.iteye.com/blog/481004
https://github.com/cometd
https://github.com/cometd/cometd.git
http://docs.cometd.org/reference/
http://abentotoro.blog.sohu.com/203996578.html

http://yaojialing.iteye.com/blog/716094

http://docs.cometd.org/reference/#d0e117

分享到:
评论

相关推荐

    comet-iframe.rar

    1. **设置PHPComet服务器**:首先,你需要在服务器上安装并配置PHPComet。这通常涉及下载源码、配置服务器环境(如Apache或Nginx)以及正确设置PHP扩展。 2. **创建IFrame HTML**:在HTML页面中插入IFrame元素,并...

    comet-atomic-2020

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

    源码部署javaTomcat-cometd:CometD项目,用于Web消息传递的可扩展Comet(服务器推送)实现

    Jetty 11.0.x - jakarta.servlet.* 6.0.x ⇒ Java 11 - 码头 10.0.x - javax.servlet.* 5.0.x ⇒ Java 8 - 码头 9.4.x - javax.servlet.* CometD许可证 CometD 源代码在 Apache 2.0 许可下发布。 项目目录布局 ...

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

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

    comet-ajax

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

    Jetty+Dojo+Tomcat的Comet配置

    cometd-api-0.9.20080221 cometd-bayeux-6.1.9 jetty-6.1.9 jetty-util-6.1.9 servlet-api-2.5-6.1.9 全网搜索dojox.cometd实现WEBQQ,没有可以运行的源码包项目,搞了五天,分享给大家,真实可用,jar包就找了好久...

    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"库很可能是一个与自然语言处理(NLP)相关的工具,尤其是考虑到其名称中包含的“unbabel”一词,这可能暗示了它的目标是解决多语言之间的沟通难题。"comet"可能是库中的核心模块或算法,可能与机器...

    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位的驱动,请用户根据自身系统选择对应的...

    Comet Reverse Ajax

    EXAMPLE CODE FOR "Comet & Reverse Ajax" by Crane & McCarthy, FirstPress 2008 GENERAL SETUP The examples presented here use Groovy on Grails, a Java-based web technology stack. More details at ...

Global site tag (gtag.js) - Google Analytics