用androidpn来实现推送

关于服务器端向Android客户端的推送,主要有三种方式:轮询,应用程序应当阶段性的与服务器进行连接并查询是否有新的消息到达,你必须自己实现与服务器之间的通信,例如消息排队等。而且你还要考虑轮询的频率,如果太慢可能导致某些消息的延迟,如果太快,则会大量消耗网络带宽和电池SMS(通过发送短信并解析短信内容来获取服务器端的指令),这个出现的问题是很难找到免费的网关来发送短信;最后就是持久连接,主要是Socket通讯,这个解决了性能问题,但是耗电问题依旧没能解决。

在这里,我们主要介绍的是第三种,用持久连接的方式来进行推送。现在比较成熟的及时消息传递协议共有四种,而无疑最为主流就是XMPP协议,它是一种基于XML的传递协议,具有很强的灵活性和可扩展性。它的特点是将复杂性从客户端转移到了服务器端。在网上可以找到很多的XMPP资料,这里就不在赘述了,不然越扯越多。总之,XMPP主要显著的优点主要有以下几个方面:

1、 分布式  任何人都可以运行自己的XMPP服务器,它没有主服务器

2、 安全性很高。使用SASL及TLS等技术的可靠安全性

3、 开发性 它是开源的,易于进行学习和了解

4、 跨平台  毋庸置疑,使用的XML进行传输的

说完优点,我们言归正传,基于XMPP协议的java开发有一个开源框架,那就是smack,它主要封装了一些XMPP的实现。而如果把它直接用在Android上是不行的,因为android缺少了一些java的类库,于是一个改进版的asmack诞生了,它是专门为android而改进的android smack。而另外一个开源框架的诞生,则是对在引用smack的基础上实现和服务器端的持久连接,以实现服务器对客户端的推送,那就是android push notification,简称androidpn

Androidpn在客户端集成了asmack。这样就可以很容易的简立一个和服务器端的基于xmpp协议的socket连接。Androidpn的客户端中,进行管理连接的类是XmppManager,它主要用来管理连接的信息,比如XMPP的端口、IP、登录的用户名密码,以及对连接的维护。为什么还有用户名和密码?这不得不提到XMPP的具体细节。整个服务器端和客户端的通信是基于一个session(会话)过程,会话开始,首先会指定服务器的端口号,然后把上述提到的信息发送到服务器端,怎么发送消息的呢?以<stream>根节点的方式开始传递,只有在服务器和客户端关闭的时候才会发送它的结束标记</stream>。客户端通过XMPP协议只用做的就是接收消息,而所有其它的操作都交给服务器,比如管理连接、消息保存等等,这样就很大程度的减轻了客户端的负担。那么客户端和服务器端的消息回应是如何实现的?如要通过一个ID来标识,具体细节可以去查看XMPP协议。

一旦注册绑定后,服务器端就和客户端建立了连接,客户端只用负责去接收消息。所以当我们应用Androidpn的时候,客户端会非常的简单。而在服务器端,Androidpn又做了什么呢?

服务器端的展示方面,androidpn主要用到的技术是SpringHibernate。主要是用来展示用户状态和发送信息用的,如以下链接:

http://www.wenjuan.com/s/aiq22e
http://www.wenjuan.com/s/JzaaEbo
http://www.wenjuan.com/s/2muQ3i
http://www.wenjuan.com/s/emm2a2
http://www.wenjuan.com/s/IJvARv
http://www.wenjuan.com/s/FBFRzqx
http://www.wenjuan.com/s/36VJrm
http://www.wenjuan.com/s/iAvQZb
http://www.wenjuan.com/s/zqQJJr
http://www.wenjuan.com/s/iUnqmm
http://www.wenjuan.com/s/Uziime
http://www.wenjuan.com/s/nMby2m
http://www.wenjuan.com/s/RnUjU3
http://www.wenjuan.com/s/2Mbyya
http://www.wenjuan.com/s/qyqEbq
http://www.wenjuan.com/s/FvyQJj
http://www.wenjuan.com/s/2uMfQj
http://www.wenjuan.com/s/m6Bray
http://www.wenjuan.com/s/6fie2i
http://www.wenjuan.com/s/riErUj
http://www.wenjuan.com/s/MfuqEfX
http://www.wenjuan.com/s/u677b2
http://www.wenjuan.com/s/aMRjea
http://www.wenjuan.com/s/FJJjUv
http://www.wenjuan.com/s/imYzE3
http://www.wenjuan.com/s/MVRBfa
http://www.wenjuan.com/s/BjaeYb
http://www.wenjuan.com/s/eiyYzq
http://www.wenjuan.com/s/iYjUv2
http://www.wenjuan.com/s/jUryAf
http://www.wenjuan.com/s/MRBR3q
http://www.wenjuan.com/s/NR3mQj
http://www.wenjuan.com/s/B7Nfmu
http://www.wenjuan.com/s/yYZZBv
http://www.wenjuan.com/s/fiuaie
http://www.wenjuan.com/s/73m2Qv
http://www.wenjuan.com/s/3m2qMb
http://www.wenjuan.com/s/3m2qMb
http://www.wenjuan.com/s/Fv2UBf
http://www.wenjuan.com/s/7RRJfi
http://www.wenjuan.com/s/aUVfqa
http://www.wenjuan.com/s/Mbq6Jb
http://www.wenjuan.com/s/J7Fjea
http://www.wenjuan.com/s/QnqqEf
http://www.wenjuan.com/s/jUN3yq
http://www.wenjuan.com/s/fQRram
http://www.wenjuan.com/s/eemAVn
http://www.wenjuan.com/s/vqmAZj
http://www.wenjuan.com/s/R3mIzy
http://www.wenjuan.com/s/RnmAra
http://www.wenjuan.com/s/EnINB3
http://www.wenjuan.com/s/EJ3m6r
http://www.wenjuan.com/s/uyYzUf
http://www.wenjuan.com/s/Zvqe22d
http://www.wenjuan.com/s/3ieyYz
http://www.wenjuan.com/s/UV3aa2
http://www.wenjuan.com/s/3uABnu
http://www.wenjuan.com/s/B3ArYv
http://www.wenjuan.com/s/YbMZru
http://www.wenjuan.com/s/NFFFVr
http://www.wenjuan.com/s/MrAFFr
http://www.wenjuan.com/s/qMrqE3
http://www.wenjuan.com/s/qMrqE3
http://www.wenjuan.com/s/FrYB3u
http://www.wenjuan.com/s/MFFNne
http://www.wenjuan.com/s/rY7Fb2
http://www.wenjuan.com/s/UNFJVr
http://www.wenjuan.com/s/UbuEfy
http://www.wenjuan.com/s/7jqM3u
http://www.wenjuan.com/s/Rjiyyi
http://www.wenjuan.com/s/MfUr2e
http://www.wenjuan.com/s/VvYFZv
http://www.wenjuan.com/s/67jQRn
http://www.wenjuan.com/s/NvAv6j
http://www.wenjuan.com/s/mM3UJj
http://www.wenjuan.com/s/UNzaqe
http://www.wenjuan.com/s/jINF3q
http://www.wenjuan.com/s/ErAzYb
http://www.wenjuan.com/s/NbEBZn
http://www.wenjuan.com/s/NFRjem
http://www.wenjuan.com/s/qmEjEf
http://www.wenjuan.com/s/iAJ3M3
http://www.wenjuan.com/s/2uEjEbm
http://www.wenjuan.com/s/VBzABz
http://www.wenjuan.com/s/rii2eq
http://www.wenjuan.com/s/vERVRf
http://www.wenjuan.com/s/uAfyYz
http://www.wenjuan.com/s/b26jUf
http://www.wenjuan.com/s/mQbmaiF
http://www.wenjuan.com/s/3aMfYj
http://www.wenjuan.com/s/3UVbqq
http://www.wenjuan.com/s/jiqUrm
http://www.wenjuan.com/s/YVnYVj
http://www.wenjuan.com/s/y2aaqa
http://www.wenjuan.com/s/Iv6re2
http://www.wenjuan.com/s/FRjAri
http://www.wenjuan.com/s/BbumUf
http://www.wenjuan.com/s/Jfamuq
http://www.wenjuan.com/s/F7ZB32
http://www.wenjuan.com/s/qqmURn
http://www.wenjuan.com/s/i6ZnQr
http://www.wenjuan.com/s/qiyaea
http://www.wenjuan.com/s/JRZrqa
http://www.wenjuan.com/s/JRZrqa
http://www.wenjuan.com/s/UvaUNf
http://www.wenjuan.com/s/Eju6Fn
http://www.wenjuan.com/s/bmAFvy
http://www.wenjuan.com/s/iiAR7f
http://www.wenjuan.com/s/3YZn6b
http://www.wenjuan.com/s/ueQzIv
http://www.wenjuan.com/s/i6jem2
http://www.wenjuan.com/s/J3qyqq
http://www.wenjuan.com/s/riiErm
http://www.wenjuan.com/s/nAJnau
http://www.wenjuan.com/s/iemm2u
http://www.wenjuan.com/s/jMjuyq
http://www.wenjuan.com/s/aYfY3y
http://www.wenjuan.com/s/F7jamm
http://www.wenjuan.com/s/2q2ayq
http://www.wenjuan.com/s/BbINr2
http://www.wenjuan.com/s/ZrMrq2P
http://www.wenjuan.com/s/v6nI7z
http://www.wenjuan.com/s/ZZVZf2
http://www.wenjuan.com/s/3i2MVf
http://www.wenjuan.com/s/iaaeqy
http://www.wenjuan.com/s/viiaYf
http://www.wenjuan.com/s/UNfaMn
http://www.wenjuan.com/s/FvIfAbh
http://www.wenjuan.com/s/Z3YFVj
http://www.wenjuan.com/s/aYNbqa
http://www.wenjuan.com/s/zYvmAz
http://www.wenjuan.com/s/fyAbmq
http://www.wenjuan.com/s/MJbe6r
http://www.wenjuan.com/s/quqMvm
http://www.wenjuan.com/s/63QzQ3
http://www.wenjuan.com/s/YfM7n2
http://www.wenjuan.com/s/7BZba2
http://www.wenjuan.com/s/NJvABf
http://www.wenjuan.com/s/YRbi2a
http://www.wenjuan.com/s/QfUBJf
http://www.wenjuan.com/s/mAbEfe
http://www.wenjuan.com/s/iiUNfyq
http://www.wenjuan.com/s/riIJNb
http://www.wenjuan.com/s/NNfuey
http://www.wenjuan.com/s/nmMRf2
http://www.wenjuan.com/s/MRB7Vb
http://www.wenjuan.com/s/jqYjeq
http://www.wenjuan.com/s/ARJNVr
http://www.wenjuan.com/s/ARJNVr
http://www.wenjuan.com/s/U3Y7fe
http://www.wenjuan.com/s/FbAZF3
http://www.wenjuan.com/s/EbuYzy
http://www.wenjuan.com/s/Mf6bia
http://www.wenjuan.com/s/J7zY7v
http://www.wenjuan.com/s/QzQ32i
http://www.wenjuan.com/s/QZfeae
http://www.wenjuan.com/s/BRRVvm
http://www.wenjuan.com/s/URRVze
http://www.wenjuan.com/s/fuYfUf
http://www.wenjuan.com/s/m63U7b
http://www.wenjuan.com/s/Mzqe6fd
http://www.wenjuan.com/s/v6jYry
http://www.wenjuan.com/s/JfY7ba
http://www.wenjuan.com/s/jEBJfm9
http://www.wenjuan.com/s/yMVjua
http://www.wenjuan.com/s/Mni2Un
http://www.wenjuan.com/s/eaIjUr
http://www.wenjuan.com/s/q2im2i
http://www.wenjuan.com/s/Nraaua
http://www.wenjuan.com/s/bYbUne
http://www.wenjuan.com/s/yquuQ3
http://www.wenjuan.com/s/vIJ7zm
http://www.wenjuan.com/s/EvmM7f
http://www.wenjuan.com/s/J3Y36jU
http://www.wenjuan.com/s/3u2mI3
http://www.wenjuan.com/s/ArQBZf
http://www.wenjuan.com/s/EJ3Mfe
http://www.wenjuan.com/s/auaaea
http://www.wenjuan.com/s/JJzUzy
http://www.wenjuan.com/s/v6biEfc
http://www.wenjuan.com/s/YRjmMv
http://www.wenjuan.com/s/3EfEvq
http://www.wenjuan.com/s/nABzUz
http://www.wenjuan.com/s/2a6zAz
http://www.wenjuan.com/s/qQzEni
http://www.wenjuan.com/s/y67RJn
http://www.wenjuan.com/s/YvyMzy
http://www.wenjuan.com/s/IB3aA3
http://www.wenjuan.com/s/IB3aA3
http://www.wenjuan.com/s/r6FBRv
http://www.wenjuan.com/s/IJRzee
http://www.wenjuan.com/s/6ZRV7v
http://www.wenjuan.com/s/26vEVvw
http://www.wenjuan.com/s/AFNnam
http://www.wenjuan.com/s/QzqyQf
http://www.wenjuan.com/s/AFNnam
http://www.wenjuan.com/s/JnUrYr
http://www.wenjuan.com/s/zMviUb
http://www.wenjuan.com/s/JZZJfq
http://www.wenjuan.com/s/vmmmeq

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。