【问题标题】:How to use Google Cloud Connection Server to send upstream GCM message如何使用谷歌云连接服务器发送上游 GCM 消息
【发布时间】:2013-06-05 08:51:57
【问题描述】:
我正在尝试使用 Google Cloud Messaging 的新云连接服务器功能将上游消息从设备发送到云端。我正在使用入门指南中的示例代码。
http://developer.android.com/google/gcm/gs.html
我能够设置客户端并获取注册 ID。但是当我发送
向服务器发送消息没有任何反应。我不确定是否需要在服务器端进行一些设置。我的基本服务器要求是接收来自客户端的消息并发回响应。我正在使用基于 Java 的后端服务器。我在有关服务器端设置的文档中找不到任何具体内容。
有人可以帮忙吗?
【问题讨论】:
标签:
java
android
push-notification
google-cloud-messaging
【解决方案1】:
是的,这绝对是可能的
http://developer.android.com/google/gcm/ccs.html
The GCM Cloud Connection Server (CCS) allows third party servers to communicate with
Android devices by establishing a persistent TCP connection with Google servers using the
XMPP protocol. This communication is asynchronous and bidirectional.
【解决方案2】:
您不能只在客户端注册到 GCM 并将消息发送到您的服务器。这只需要处理您的设备和 GCM 服务器之间的连接。
您必须设置您的服务器与 GCM 云连接服务器 (CCS) 的连接,以便能够在您的服务器上发送和接收消息:
GCM 云连接服务器 (CCS) 是一个 XMPP 端点,运行于
http://gcm.googleapis.com 5235 端口。
CCS 需要传输层安全 (TLS) 连接。这意味着
XMPP 客户端必须启动 TLS 连接。例如在 smack 中,
你会调用 setSocketFactory(SSLSocketFactory),类似于“old
样式 SSL” XMPP 连接和 https。
CCS 需要使用 SASL PLAIN 身份验证机制
@gcm.googleapis.com(GCM 发件人 ID)和 API
key 作为密码,其中发送者 ID 和 API 密钥相同
入门中描述。
您可以使用大多数 XMPP 库与 CCS 进行交互。