Push

1.苹果APNs使用的协议:XMPP协议。

XMPP核心协议通信的基本模式就是先建立一个stream,然后协商一堆安全之类的东西,中间通信过程就是客户端发送XML Stanza,一个接一个的。服务器根据客户端发送的信息以及程序的逻辑,发送XML Stanza给客户端。但是这个过程并不是一问一答的,任何时候都有可能从一个方发信给另外一方。通信的最后阶段是关闭流,关闭TCP/IP连接。

2.Long Polling

目前最为流行的一种做法称 为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)
3.APNs
APNs uses a persistent IP connection for implementing push notifications.
 

 

 

posted on 2011-05-27 16:51  Alwaysyouare  阅读(313)  评论(0编辑  收藏  举报

导航