Push Technology概述 (一)

废话:

自己最近的一些读书笔记和心得。再次声明,希望详细了解相关内容的,可以自己查看引用文献。

再唠叨一句,写blog不支持上传图片,CSDN干脆关门算了!

 

简介

随着诸如Twitter和FriendFeed这类应用的流行,一种新的Client和Server交互的方式: Push technology也日益变得普遍。顾名思义,Push Tech指的是server端将最新的message(当前发生的news或者好友的最新动态)主动的发送到client端。

以前最常见到的使用push tech的程序是Instance Message,A的好友B给A发送的message会先传递到IM的server端,然后由server端push给A。而现在,push tech之所以越来越重要,是因为Twitter的火爆让大家看见了real-time web这类应用程序的前景,而push tech正是real-time web的核心技术【1】。

本着考古的精神,找到了最早的一篇1996年关于Push Tech的文章,文章中构造了一个程序PointCast,server端会将最新的新闻push到client端上。可以看出,早期的使用push Tech的程序,包括这些个聊天工具,都要安装一个client端程序,client端和server之间维持一个持久链接,然后通过某一种协议进行交互,一旦server端有最新的消息,就将这个消息通过持久链接发送到client端。现在,比较常见的用于push tech中进行交互的协议就是XMPP,包括很多的IM工具(如gmail等)都使用此协议。

和Push Tech对应的就是传统的Pull Tech,即用户主动的操作以获取信息。比如Web 2.0中最常见的RSS。第一感觉RSS似乎是Push Tech,因为RSS总是能将你关注的web feed的最新动向告诉你,但其实,RSS是典型的Pull Tech,因为它需要你主动的点击,然后RSS reader再去相关的web feed将更新的内容pull过来。其实,大部分的互联网应用都属于Pull Tech。原因可能是因为互联网最核心的协议HTTP本身并不支持Push的功能。HTTP所有的交互几乎都是由client发起,client端发送一个request,server端接收处理,然后向client发送response。

那么,这就有一个问题了:怎样在HTTP上,或者更大范围的说,怎样在web上实现Push Tech。

 

Web上的Push Tech实现

最简单的一种方法,就是client端频繁的pull(比如间隔几秒),以达到push的效果。但是它的副作用也很明显,首先,网络开销大,server端的压力也大,其次,这种方式仍然不是真正意义上的real-time push。

目前最为流行的一种做法称为Long Polling。它是利用传统的pull tech来实现real-time的push效果。具体的做法是,client向server端发送一个request(比如http request,属于pull tech),如果server端有最新的信息,那么就立即回复给client,如果没有,那么并不立刻回复,而是等待一定的时间(比如十几秒),在这十几秒中内,如果server端获得了最新的信息(或者timeout),那么再回复给client。无论何种情况,当client收到server发回的response,这次cycle就结束了,client会立刻启动新的交互,再次向server发送一个request。这样,可以保证server端最新的消息能够实时的被传送到client端。
(Long polling is a variation of the traditional polling technique and allows to emulate information push from a server to a client. With long polling, the client requests information from the server in a similar way to a normal poll. However, if the server does not have any information available for the client, instead of sending an empty response, the server holds the request and waits for some information to be available. Once the information becomes available (or after a suitable timeout), a complete response is sent to the client. The client will normally then immediately re-request information from the server, so that the server will almost always have an available waiting request that it can use to deliver data in response to an event. --- from wiki)
   

另外一个需要提及的词是“Comet”【3】。Comet其实是一个涵盖性术语(umbrella term),泛指那些基于HTTP长链接,无需在web brower上安装插件就能够实现server push的技术(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)。
常用的comet模型有两种:一种基于Ajax的long polling,一种是基于 Iframe 及 htmlfile 的流(streaming)方式,不详细说了,具体的介绍见参考文献【4】。

还有一种方法叫做“BOCH”【5】,它貌似是在client与server上通过HTTP协议建立一个双工的connection,然后在上面跑XMPP来实现push tech。我也不太了解,不知道叙述的是否正确,有兴趣的可以自己去查资料。

 

(待续)

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值