powered by Jive Software

PacketListener for the Connection

Does anyone know how I have to implement the listener to add to the connection for listen the incoming message???

THANKS

If you want to listen out for messages you could do something like

1

2

3

4

5

6

7

8

9

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);

}

};

You would then need to add this listener to your connection

1

connection.addPacketListener(myListener, filter);

Where filter is the type of filter you want to apply which in this case is for type Message

1

PacketTypeFilter filter = new PacketTypeFilter (Message.class);

See my post here for how to add a listener to listen out for messages of type CHAT

http://www.jivesoftware.org/community/thread.jspa?threadID=18428&tstart=0