问题
i am trying to implement pubsub using openfire
server and asmack
library.
i have configured my node in such a way that subscribers
has to take the approval of publishers
now i am trying to read the Message
packet using following code but i am not getting any packet. i want to read Message
packet because i want to know whenever the subscribers send the request to publishers to get subscribe.
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);
All i want is to read the incoming Message Packets
回答1:
If you have all the configuration bits and your pubsub component correctly working, then for getting a normal message you would do something like:
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);
来源:https://stackoverflow.com/questions/13777234/read-incoming-message-packets-in-pubsub-using-smack