GCM消息不是并行发送的,聊天用户必须等待很长时间

时间:2015-02-06 14:57:12

标签: android xmpp google-cloud-messaging

我有一个使用XMPP服务器的Android聊天应用程序(我制作)< ===> GCM用于消息传递。

所有消息(上游和下游)都是通过GCM:

[设备] ---> GCM ---> [xmpp]和[xmpp] - > GCM ---> [设备]

当服务器同时向GCM发送许多消息(即广播)时,其他消息不会从设备到达服务器(GCM忙),直到xmpp服务器发送所有消息为止到GCM,然后它可以通过GCM从用户接收新消息。 这是发送功能:

  public void send(String jsonRequest) {
        Packet request = new GcmPacketExtension(jsonRequest).toPacket();
        connection.sendPacket(request);
    }

更新

 connection.addPacketListener(new PacketListener() {

        @Override
        public void processPacket(Packet packet) {
            logger.log(Level.INFO, "[{0}]  {1}", new Object[]{Tools.getFormatedTime(), packet.toXML()});
            //Message incomingMessage = (Message) packet;

            GcmPacketExtension gcmPacket
                    = (GcmPacketExtension) ((Message) packet).getExtension(GCM_NAMESPACE);
            String json = gcmPacket.getJson();
            try {
                @SuppressWarnings("unchecked")
                Map<String, Object> jsonMap
                        = (Map<String, Object>) parseWithException(json);




 handleMessage(jsonMap);
            } catch (ParseException e) {
                logger.log(Level.SEVERE, "Error parsing JSON " + json, e);
                System.err.append("Error parsing JSON " + json+ " " +e);
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Couldn't send echo.", e);
                     System.err.append("Couldn't send echo."+e);
            }
        }
    }, new PacketTypeFilter(Message.class));

0 个答案:

没有答案