PacketListener not receiving data once message has been sent

I was hoping somebody would be able to help me with this. I have set up an XMPPConnection and added a PacketListener to it but i am unable to receive messages over Jabber once a message has been sent. However, if i regularly remove the listener, close the XMPPConnection and reset it, adding the packetlistener again it all works fine (apart from my application slowly eating all memory). Could somebody advise me of the best (of the proper) way to set up up a packetlistener so it can send (and also receive) messages. Many thanks

I should say that i’‘m on Windows XP Pro, with a VB front end. I send messages using Jabber and a Java process is constantly running which has an XMPPConnection and is listening for packets of data. As stated, if the connection is closed and opened regularly i can receive and send data but my memory on the java app increases. If i don’‘t reset the connection i can send a message to another app, but once sent i can’'t receive any. Any help would be greatly appreciated.

What version of Smack are you using? And, can you post some code snippets so that we can understand better what you’'re doing?

Thanks,

Matt

Thanks for replying. I am using smack 1.2.1. I’'ve enclosed some snippets of code as requested. The initialise method is called which sets up the XMPPConnection. Then the doProcess loops and will create the listener (first time only). It works one way unless i recreate the XMPPConnection constantly in the doProcess method.

Hope i haven’'t been to confusing as i am quite new to java. Thanks for your time.

public class JabberNotification extends AbstractProcessor {

private XMPPConnection jabberConnection;

private MessageListener listener;

public void doProcess() throws FatalException {

if(firstTime){

listener =new MessageListener(…);

PacketFilter filter = new PacketTypeFilter(Message.class);

jabberConnection.addPacketListener(listener, filter);

}

}

public void initialise() throws …

try {

XMPPConnection.DEBUG_ENABLED = debug;

jabberConnection = new XMPPConnection(jabberServer);

jabberConnection.login(

jabberUsername,

jabberPassword,

RESOURCE_NAME);

} catch (XMPPException e) {

}

}

}

public class MessageListener implements PacketListener {

public void processPacket(Packet packet) {

if (packet instanceof Message) {

try { …

}

Can you post your entire doProcess method? I don’‘t understand why it’'s a loop… you should just add the listener in the initialize method.

-Matt

Matt,

I’'ve enclosed the full doProcess method, which loops to see if the connection and the listener are up and running. As you state, i could put the setup of the listener in the initialize method.

public void doProcess() throws FatalException {

if (!jabberConnection.isConnected()) {

log.info(“Restarting Jabber Connection”);

throw new FatalException();

}

if (firstTime) {

// Set up the listeners

listener =

new MessageListener(

getDatabaseUrl(),

oracleUsername,

oraclePassword);

PacketFilter filter = new PacketTypeFilter(Message.class);

jabberConnection.addPacketListener(listener, filter);

firstTime = false;

}

if (!listener.alive){

log.error(“Detected Failed Jabber Listener - restarting”);

throw new FatalException();

}

try {

Thread.sleep(100);

} catch (InterruptedException e) {

log.error(“Interupted - should not have been”);

throw new FatalException();

}

}