【问题标题】:Android XMPP Server in Java From Google Docs来自 Google Docs 的 Java 中的 Android XMPP 服务器
【发布时间】:2014-11-26 13:23:40
【问题描述】:

我正在尝试按照Google Doc 创建一个服务器来处理 Android GCM 的 XMPP。

public static void main(String[] args) throws Exception {
    final long senderId = PROJECT_ID;
    final String password = "API_KEY";

    XMPPServer00 ccsClient = new XMPPServer00();

    ccsClient.connect(senderId, password);

    // Send a sample hello downstream message to a device.
    String toRegId = "REGISTRATION_ID";
    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);
}

到目前为止,服务器能够向客户端发送下游消息,但客户端无法向服务器发送上游消息。

Nov 26, 2014 6:07:43 PM XMPPServer00$LoggingConnectionListener authenticated
INFO: Authenticated.
Nov 26, 2014 6:07:43 PM XMPPServer00$3 interceptPacket
INFO: Sent: <message id='4259t-2'><gcm xmlns="google:mobile:data">   {&quot;to&quot;:&quot;API_KEY&quot;,&quot;delay_while_idle&quot;:true,&quot;collapse_key&quot;:&quot;sample&quot;,&quot;data&quot;:{&quot;EmbeddedMessageId&quot;:&quot;m-b9731a48-7730-40d6-a52e-2ea9253c85ca&quot;,&quot;title&quot;:&quot;World&quot;,&quot;CCS&quot;:&quot;Dummy Message&quot;},&quot;message_id&quot;:&quot;m-b9731a48-7730-40d6-a52e-2ea9253c85ca&quot;,&quot;time_to_live&quot;:10000}</gcm></message>`

查看我从谷歌复制的代码,它创建连接,然后向设备发送下游消息,然后完成。 如果我没记错的话,谷歌文档说第三方服务器和谷歌服务器之间需要有持久连接。

connection.addPacketListener(new PacketListener() {

        @Override
        public void processPacket(Packet packet) {
        ...

在connect()内部,它创建了一个监听器来处理上游消息,但是由于程序在发送下游消息后结束,所以这个监听器也结束了对吧?

另一个问题,与其使用运行的服务器应用程序,不如创建一个 servlet/webapp 来处理 xmpp?

【问题讨论】:

    标签: java xmpp google-cloud-messaging


    【解决方案1】:

    我是对的。主要功能正在结束,因此整个程序结束。我解决它的方法是使用一个新线程来运行它并保持它运行,现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      相关资源
      最近更新 更多