Android的GCM:了解XMPP [英] Android GCM : understanding XMPP

查看:286
本文介绍了Android的GCM:了解XMPP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的应用程序来实现我的GCM一个XMPP协议,但即使经过广泛的搜索,我不明白的概念,它的后面。

I'm trying to implement a XMPP protocol in my GCM using app, but even after searching extensively, I don't understand the concepts behind it.

另外,也许我并不真的需要XMPP什么我想做的事与我的应​​用程序,但我想学的东西。

Also, maybe I don't really need XMPP for what I want to do with my app, but I like to learn things.

让我们来盘点一下我可以做HTTP这个例子:

Let's take this example of what I could do with HTTP :

  1. 我的应用程序发送你好词和REGID我的小的personnal服务器: url.openConnection(),然后的OutputStream 发送POST数据和的InputStream 获取响应

  1. my app send "hello word" and the regId to my little personnal server : url.openConnection(""), then OutputStream for sending POST data and InputStream for getting the response

服务器,在这个URL,把你好词消息与REGID一个数据库,然后使用PHP的curl库将数据发送到GCM服务器,如<$ C $ JSON字符串C> {myResponse:我不是世界上我是丹} (使用测试世通ID,在仿真器)

the server, at this url, put the "hello word" message in a database with the regId, and then use the curl library of php to send data to GCM servers as a json string like {"myResponse":"I'm not world I'm Dan"} (using a test destinator id, in an emulator)

GCM服务器做他的生意

GCM server do his business

我的应用程序(可能在另一部手机),使用 IntentService WakefulBroadcastReceiver 即得到消息为 intent.getExtras()的getString(myResponse)

my app (maybe on another phone) use an IntentService in a WakefulBroadcastReceiver that get the message as intent.getExtras().getString("myResponse")

这工作得很好,我可以从一个手机采用我的应用程序,并通过收集我的服务器上的数据的方式将消息发送到另一台。

This works well and I could send messages from one phone to another using my app, and collecting data on my server the way through.

是这样的处理HTTP OK theorically? (我看了很多帖子和教程,尤其是谷歌的人,但还是不知道)

Is this way of handling HTTP ok theorically ? (I saw a lot of posts and tutorials, especially Google ones, but still not sure)

有哪些步骤做相同的XMPP?

What are the steps to do the same with XMPP ?

我不想要一个教程或c $ CS件$,我想了解的信息经过这个协议,我不熟悉的方式(我设法在我的服务器上安装的ejabberd,用洋泾浜我PC和Xabber在我的手机)。

I don't want a tutorial or pieces of codes, I want to understand the way the info goes through this protocol I don't know well (I managed to install ejabberd on my server and use pidgin on my PC and Xabber on my phone).

推荐答案

官方定义

在谷歌云消息(GCM)云连接服务器(CCS)是一个   XMPP端点提供了一个持续的,异步,双向   连接到谷歌服务器。

The Google Cloud Messaging (GCM) Cloud Connection Server (CCS) is an XMPP endpoint that provides a persistent, asynchronous, bidirectional connection to Google servers.

建立与CCS的连接是这里的第一个也是最重要的一步。一旦你完成这点,保持长期连接,其他部分没有那么棘手。

Establishing a connection with CCS is the first and most important step here. Once you are done with this and maintain a long-lived connection, other parts are not that tricky.

两者之间的一些差异:
1)与HTTP与XMPP的消息,你并不需要包括认证报头与每一个有效载荷,因为服务器的连接,我们保持相同的连接时进行身份验证。
2)CCS使用XMPP协议作为传输层,因此在成功建立连接,您可以交换节。
3)你可以继续使用HTTP的下游,但并使用XMPP只为上游,如果你想。
4)代替 registration_ids 参数使用到:在XMPP,我们只能通过一个节发送给一个REGID

Some differences between the two:
1) Unlike HTTP, with XMPP messages you do not need to include Authentication headers with every payload since server is authenticated at the time of connecting and we are maintaining the same connection.
2) CCS uses XMPP as a Transport Layer and therefore after you have successfully established connection you can exchange stanzas.
3) You could keep using HTTP for downstream though and use XMPP only for upstream if you wish.
4) Instead of registration_ids param use to: in XMPP and we can only send to one RegID through one stanza.

所以,如果我要解释你的榜样,将与XMPP:
- 建立与CCS
连接 - 发送href="https://developers.google.com/cloud-messaging/upstream" rel="nofollow">上游讯息从客户端服务器的 - 一旦确认您的服务器发送ACK到GCM
收到此消息 - 对于
下游你有选择使用HTTP或XMPP
的消息 - 但是,如果XMPP:接收,保存在数据库中,并发送响应时( {myResponse:我不是世界上我是丹} )返回给客户端(相同或不同的REGID)发送下行节到CCS; CCS将发送ACK / NACK以确认它已收到消息
- 您还将收到delivery_receipt(如果需要),一旦客户端应用程序已收到消息。

So if I were to explain how your example would work with XMPP:
- Establish a connection with CCS
- Send an upstream message to your server from the client "Hello, World!"
- Acknowledge once your server receives this message by sending ACK to GCM
- For downstream message you have choice of using either of HTTP or XMPP
- But if XMPP: receive, save in database and when sending response ({"myResponse":"I'm not world I'm Dan"}) back to the client (same or different RegID) send a downstream stanza to CCS; CCS will send ACK/NACK to acknowledge that it has received the message
- You will also receive delivery_receipt (if requested) once the client app has received the message.

除此之外,你可以通过阅读,我整个帖子都链接官方​​文档了解更为深入。

Other than this, you can understand more in depth by reading the official documentation which I have linked throughout the post.

希望这有助于!

这篇关于Android的GCM:了解XMPP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆