收到Xmpp消息,属性丢失

时间:2015-01-27 08:04:46

标签: android xmpp smack

我正在使用xmpp和ASMACK android-8-4.0.6开发小型聊天应用程序。在发送消息时,服务器向我发送回复以确认消息已成功到达服务器。回复如下:

<message to="abc@ofsrv1"><a xmlns="urn:xmpp:sm:3" h="6vO1d-7"/></message>

其中属性&#39; h&#39; inside元素包含已发送消息的包ID。我发送消息如下

public void sendMessage(String to, String messageData)
    {
        try
        {
            Message msg = new Message(to, Message.Type.chat);
            addMessageToLocalDb(to, messageData, msg.getPacketID());
            msg.setBody(messageData);
            DeliveryReceiptManager.addDeliveryReceiptRequest(msg);
            xmppConnection.sendPacket(msg);

        } catch (Exception e)
        {

        }
    }

我附加了数据包监听器,我收到了服务器的回复,但收到的表格如下:

<message to='sender@ofsrv1'><a xmlns='urn:xmpp:sm:3'></a></message>

其中&#39; h&#39;元素中的属性显然缺失。有趣的部分是我的日志猫,在&#34; SMACK&#34;标签我收到了完整的回复以及h属性如下

<message to="sender@ofsrv1"><a xmlns="urn:xmpp:sm:3" h="6vO1d-7"/></message> 

所以服务器回复成功到达Android客户端但是一些附加的数据包监听器没有收到它。用于附加数据包侦听器的代码是

public void configureConnection()
    {
        try
        {
            //PacketFilter filter1 = new IQTypeFilter(IQ.Type.RESULT);
            PacketFilter filter = new PacketFilter()
            {
                @Override
                public boolean accept(Packet packet)
                {
                    return true;
                }
            };
            XmppPacketListener xmppPacketListener = new XmppPacketListener(this, xmppConnection);
            xmppConnection.addPacketListener(xmppPacketListener, filter);

            //Registering Delivery receipt Listener
            deliveryReceiptManager = DeliveryReceiptManager.getInstanceFor(xmppConnection);
            XmppReceiptReceivedListener receiptReceivedListener = new XmppReceiptReceivedListener();
            deliveryReceiptManager.addReceiptReceivedListener(receiptReceivedListener);

            //Enabling carbons
            CarbonManager carbonManager = CarbonManager.getInstanceFor(xmppConnection);
            if (carbonManager.isSupportedByServer())
            {
                carbonManager.sendCarbonsEnabled(true);
            }

        } catch (Exception e)
        {
            CustomLogger.showLog("Xmpp", "Error in configuring xmpp connection" + e.toString());
        }
    }


public class XmppPacketListener implements PacketListener
{

    private XMPPConnection mXmppConnection;

    private Context mContext;



    public XmppPacketListener(Context context, XMPPConnection xmppConnection)
    {
        CustomLogger.showLog(TAG, "Packet listener init");
        this.mContext = context;
        this.mXmppConnection = xmppConnection;
    }

    @Override
    public void processPacket(Packet packet)

    {

        try
        {
            CustomLogger.showLog("Message", "Received packet" + packet);



        } catch (Exception e)
        {

        }
    }
}

任何人都可以帮我弄清楚接收数据包时到底缺少了什么 非常感谢任何帮助

0 个答案:

没有答案