0

我正在尝试使用openfire服务器和asmack库来实现 pubsub。subscribers我已经以必须获得批准的方式配置我的节点publishers

现在我正在尝试Message使用以下代码读取数据包,但我没有收到任何数据包。我想阅读Message数据包,因为我想知道订阅者何时向发布者发送请求以获取订阅。

PacketTypeFilter filter = new  PacketTypeFilter(org.jivesoftware.smack.packet.Message.class);

    PacketListener myListener = new PacketListener(){

        @Override
        public void processPacket(Packet packet) {
            // TODO Auto-generated method stub

            Log.d("PACKET" , "READ");

            if(packet instanceof org.jivesoftware.smack.packet.Message){

                    org.jivesoftware.smack.packet.Message msg = (org.jivesoftware.smack.packet.Message) packet;

            Log.d("MY MESSAGE" , msg.toXML()+ "");


                    }
                }

            };

    cxmpp.addPacketListener(myListener, filter);

我想要的只是阅读传入的消息包

4

1 回答 1

1

如果您拥有所有配置位并且您的 pubsub 组件正常工作,那么为了获得正常消息,您可以执行以下操作:

ConnectionConfiguration config = new ConnectionConfiguration("ADDRESS",PORT); // service name, also known as XMPP domain of the target server. 
config.setServiceName(this.pubsubServiceAddress);
connection = new XMPPConnection(config);
connection.connect();

PacketFilter filter = new MessageTypeFilter(Message.Type.normal); 

connection.addPacketListener(new PacketListener() { 
    public void processPacket(Packet packet) {
    Message mes = (Message)packet;
        // do your stuff here
    }
}, filter);
于 2012-12-25T13:43:15.170 回答