powered by Jive Software

Pubsub: Parsing a received Message


I have written two clients which subscribe and publish to each other. One client publishes information by creating an IQ message and sending the message to the node. The second client subscribes to the node and receives messages by using a PacketListener:

con.addPacketListener(new PacketListener() {

public void processPacket(Packet packet) {

if (packet instanceof Message)

System.out.println(“I got a message”);

System.out.println("Packet = " + packet.getClass().toString());

System.out.println(“TRYING TO PARSE!!!”);

System.out.println(“About to parse the body of the message”);

Message message = (Message)packet;

System.out.println("The Message Body is " +


System.out.println(“Message to XML” + message.toXML());

System.out.println(“Type=” + message.getType());

System.out.println("Packet is from " + packet.getFrom());


}, new PacketTypeFilter(Message.class));

The when a message is published to the node, the second client (that is subscribed to the node) receives the following XML message (In the debug window)