我正在尝试使用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);
我想要的只是阅读传入的消息包
答案 0 :(得分: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);