Android 谷歌云消息-服务器端

Android 谷歌云消息-服务器端,android,xmpp,google-cloud-messaging,instant-messaging,Android,Xmpp,Google Cloud Messaging,Instant Messaging,我需要一些关于gcm服务器端的帮助。 我正在用服务器端的例子开发即时消息应用程序 在我执行这段代码后,它会连接,但几秒钟后就会终止。我猜这是因为main()函数 public static void main(String[] args) throws Exception { final long senderId = 1234567890L; // your GCM sender id final String password = "Your API key";

我需要一些关于gcm服务器端的帮助。 我正在用服务器端的例子开发即时消息应用程序

在我执行这段代码后,它会连接,但几秒钟后就会终止。我猜这是因为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);
}
publicstaticvoidmain(字符串[]args)引发异常{
最终长发送者id=1234567890L;//您的GCM发送者id
final String password=“您的API密钥”;
SMAKCCSClient CCSCClient=新的SMAKCCSClient();
ccsClient.connect(senderId,密码);
//向设备发送示例hello下游消息。
String toRegId=“RegistrationIdOfTheTargetDevice”;
字符串messageId=ccsClient.nextMessageId();
Map payload=newhashmap();
payload.put(“你好”,“世界”);
有效载荷put(“CCS”,“虚拟消息”);
payload.put(“EmbeddedMessageId”,messageId);
字符串collapseKey=“sample”;
长期寿命=10000升;
String message=createJsonMessage(toRegId、messageId、payload、,
collapseKey,timeToLive,true);
ccsClient.sendDownstreamMessage(消息);
}
  • 难道不应该是一个“while”语句来保持app服务器到GCM服务器之间的XMPP连接处于活动状态吗

  • 在这种情况下,服务器端(即时消息应用程序)的目的不是保持与GCM服务器的连接,并侦听来自客户端的传入消息。 信息如下: 2.1当客户端想要注册应用程序时,我需要将其详细信息存储在数据库中。 2.2当客户端希望向另一个客户端发送消息,以便服务器端应用程序负责将消息转发到其目的地时


  • 我已经寻找了两个使用xmpp实现gcm服务器端的示例,它们都具有我上面提到的这种主要功能。。。我有什么不对劲吗

    是的,XMPP连接必须保持活动状态。否则,您的服务器将无法接收上游(设备到云)消息


    我说不出为什么你看到的所有例子都没有保持开放的联系。我想这些都是简单的例子。

    嘿,谢谢你的回答。我问了同样的问题,他们的回答不同。。。你能看看他的答案吗?此外,谢谢,我现在已经在Wireshark中进行了检查,以查看连接是否正常,从哪里可以获得这样一个服务器的模板?我不明白谷歌给我的例子该怎么办。@RonDaniel你能维持连接吗?