PacketListener is used for listen the incoming messages and work with them??? how I can use it?
THANKS!
PacketListener is used for listen the incoming messages and work with them??? how I can use it?
THANKS!
If you want to listen out for messages you could do something like
PacketListener myListener = new PacketListener() {
public void processPacket(Packet packet) {
// do something with your packet here
Message message = (Message)packet;
String from = message.getFrom();
String body = message.getBody();
System.out.println("Message from: " + from + " " + body);
}
};
/code
You would then need to add this listener to your connection
connection.addPacketListener(myListener, filter);[/code]
Where filter is the type of filter you want to apply which in this case is for type Message
PacketTypeFilter filter = new PacketTypeFilter (Message.class);[/code]