【发布时间】:2014-10-26 02:26:06
【问题描述】:
我需要一些帮助来了解有关 gcm - 服务器端的一些事情。 我正在使用服务器端示例开发即时消息应用程序http://developer.android.com/google/gcm/ccs.html
执行此代码后,它连接但几秒钟后终止。我可以猜到这是因为 main() 函数的原因。
public static void main(String[] args) throws Exception {
final long senderId = 1234567890L; // your GCM sender id
final String password = "Your API key";
SmackCcsClient ccsClient = new SmackCcsClient();
ccsClient.connect(senderId, password);
// Send a sample hello downstream message to a device.
String toRegId = "RegistrationIdOfTheTargetDevice";
String messageId = ccsClient.nextMessageId();
Map<String, String> payload = new HashMap<String, String>();
payload.put("Hello", "World");
payload.put("CCS", "Dummy Message");
payload.put("EmbeddedMessageId", messageId);
String collapseKey = "sample";
Long timeToLive = 10000L;
String message = createJsonMessage(toRegId, messageId, payload,
collapseKey, timeToLive, true);
ccsClient.sendDownstreamMessage(message);
}
不应该是一个“while”语句来保持应用服务器和 GCM 服务器之间的 XMPP 连接处于活动状态吗?
在这种情况下,服务器端(即时消息应用程序)的目的是保持与 GCM 服务器的连接并监听来自客户端的传入消息。 像这样的消息: 2.1 当客户想要注册到应用程序时,我需要将它的详细信息存储在数据库中。 2.2 当客户端要向另一个客户端发送消息时,服务器端应用负责将消息转发到它的目的地?
我已经寻找了几个使用 xmpp 实现 gcm 服务器端的示例,所有这些示例都具有我上面提到的这种主要功能......我有什么问题吗?
【问题讨论】:
标签: android xmpp google-cloud-messaging instant-messaging