Android的GCM:了解XMPPAndroid、GCM、XMPP

2023-09-06 22:34:59 作者:别再矫情

我想使用的应用程序来实现我的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 :

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

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服务器,如 {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">上游讯息从客户端服务器的