ajax push
很多应用譬如监控、即时通信、即时报价系统都需要将后台发生的变化实时传送到客户端而无须客户端不停地刷新、发送请求.基于客户端套接口的“服务器推”技术
1.Flash XMLSocket
这种方案实现的基础是:
Flash 提供了 XMLSocket 类。
JavaScript 和 Flash 的紧密结合:在 JavaScript 可以直接调用 Flash 程序提供的接口。
2.Java Applet 套接口
在客户端使用 Java Applet,通过 java.net.Socket 或 java.net.DatagramSocket 或 java.net.MulticastSocket 建立与服务器端的套接口连接,从而实现“服务器推”。
基于 HTTP 长连接的“服务器推”技术
1.基于 AJAX 的长轮询(long-polling)方式
<img width="354" height="276" alt="">
2.基于Iframe 及 htmlfile 的流(streaming)方式
<img width="324" height="314" alt="">
Comet
Comet的客户端有基于javascript的cometd-dojox,基于java的cometd-jetty,基于flex的flexcomet。
Server端有基于java的comtd-java和ibm的Feature Pack for Web 2.0。
Comet的主要逻辑如下:
用基于http的长连接来进行消息通信。客户端先向服务器端发送一个httprequest,服务器端接收到后,阻塞在那边,等服务器有消息的时候,则返回一个httpresponse给客户端,客户端收到后,断开连接,紧接着再发第二个httprequeest,以此反复进行,保持这个“长连接”。期间,如果连接超时,那么会断开重连,以保持连接。
Bayeux协议
Bayeux协议是基于Json格式的,client和server直接的发布订阅消息协议。这个协议基于http,允许在普通http情况下,参与者之间的异步消息。
一般情况下,在http协议中,client要想获得server的消息,必须先自己发送一个request,然后server才会给予response。而Bayeux协议改变了这个情况,他允许server端异步push自己的消息到client端。从而实现了client和server之间的双向操作模式(bi-directional communications)。
主要逻辑如下:
Client和server直接先通过握手协议,互相发送request和response进行握手;如果握手成功,那么client再向server发送connect request,server接着发送connect response,如果这步也成功,那么client和server之间的Bayeux协议连接成功。否则,要返回开始重新进行握手协议。
BC ----------------------------------------- BS
| ------------------ handshake request ---> |
| <-- unsuccessful handshake response ----- |
| ------------------ handshake request ---> |
| <-- successful handshake response ------- |
| -------------------- connect request ---> |
~ ~ wait
| <------ connect response ---------------- |
| -------------------- connect request ---> |
| <---- unsucessful connect response ------ |
| ------------------ handshake request ---> |
| <-- successful handshake response ------- |
| -------------------- connect request ---> |
~ ~ wait
| <------ connect response ---------------- |
Ajax Push Engine
Ajax Push Engine是一个全功能的开源AjaxPush框架。Ajax PushEngine包含一个comet服务器和一组JavaScript框架,二者结合起来可以打造出一个完整的基于Ajax的comet解决方案。AjaxPushEngine可以再不安装任何客户端程序的前提下实时与浏览器进行数据交互。随着web2.0时代的买进,ajax应用逐渐深入人心,笔者首次接触到comet应用应该是在Java下著名的Servlet容器Jetty6.1.1x的版中,该版本自带了一个comet的demo,是一个无刷新的聊天室应用。Ajax PushEngine曾经被命名为Ajax Chat Engine始与2006年,后来开发者决定创造出一个更优秀的基于Ajax Push技术的版本,于是Ajax Push Engine诞生了。
Ajax Push Engine拥有如下四大特点:
[*]Ajax Push Engine采用标准的xmlhttp技术,无需客户端安装任何插件
[*]Ajax Push Engine不依赖浏览器,不受平台限制,Ajax Push Engine的数据传递直接与浏览器交互
[*]Ajax Push Engine采用的是push技术,该技术可以与浏览器实时交互数据
[*]Ajax Push Engine是100%开放源码的框架,并且绝对免费,无论是商业使用还是非商业使用都没任何限制(Ajax Push Engine采用GNU Public Licence version 2发布)
Ajax Push Engine下载地址:
http://nocache.ape-project.org/files.php?f=APE-Project_1.0.tar.gz&v=1.0
Ajax Push Engine下载(pdf文档,适合入门学习)
http://www.ape-project.org/var/comics_pdf/APE-Comics_Chapter1.pdf
Ajax Push Engine在线文档:
http://www.ape-project.org/docs/
http://www.ape-project.org/comics/1/Chapter-I-common-let-s-push.html
Ajax Push Engine官方主页:
http://www.ape-project.org
CometD
CometD是一个提供多种开发语言的Bayeux项目,可支持JavaScript, Java, Perl, Python等语言,由Dojo基金会提供支持。CometD 是一个使用了 Ajaxpush技术的可伸缩的基于HTTP的事件路由总线程序,这项技术也叫 Comet。
近日,CometD发布了1.0最终版本,而且对2.0版本的开发也在展开。
[*]better support for tweaking the configuration
[*]split configuration and initialization steps to allow more flexibility in case of programmatic disconnects
[*]extended and clarified the Cometd APIs
[*]better notifications for failures due to server or network failures
[*]automatic and configurable connection retries
[*]incoming message and outgoing message interception
[*]automatic bayeux transport negotiation, supporting long-polling and callback-polling transports
[*]extensions such as timesync, message acknowledgement and transparent page reload
PUSHLET
http://www.iteye.com/topic/89158
http://www.javaworld.com/jw-03-2000/jw-03-pushlet.html
http://www.pushlets.com/
页:
[1]