powered by Jive Software

Weird "Not connected to server" message

Hi,

I’ve created a simple sender / receiver web app using smack. It works fine, every message reachs it’s destination.

The only problem is, I get those weird “Not connected to server” log messages. Even if those exceptions are thrown, my message reaches its destination. How is that possible?

The example code:

Main class:

public class MessageReceiver {     private XMPPConnection connection;
     private Timer timer;
     private TimerTask sendTask;     public MessageReceiver(final String user,
             final String password, final int repeatTime) {         connection = new XMPPConnection("chat.XXX.de");
         try {
             connection.connect();
             connection.login(user, password);             initListener();
             initSender(repeatTime);
         } catch (Exception ex) {
             System.err.print(ex);
         }
     }     private void initListener() {
         PacketFilter filter = new PacketTypeFilter(Message.class);
         PacketListener listener = new PacketListener() {             public void processPacket(Packet packet) {
                 try {
                     Message m = (Message) packet;
                 } catch (Exception ex) {
                     System.err.print(ex);
                 }
             }
         };         connection.addPacketListener(listener, filter);
     }     private void initSender(int repeatTime) throws InterruptedException {
         sendTask = new MessageSender(connection);         timer = new Timer();
         timer.scheduleAtFixedRate(sendTask, 5000, repeatTime);
     } }

Message sender

public class MessageSender extends TimerTask {     private XMPPConnection connection;
     private Random rand;
     private long cnt = 0l;     public MessageSender(final XMPPConnection connection) {
         this.connection = connection;
         rand = new Random();
     }     @Override
     public void run() {
         try {
            cnt++;
             Message m = new Message("testclient@chat.XXX.de");
             m.setBody(String.valueOf(cnt));
             connection.sendPacket(m);
         } catch (Exception e) {
             System.err.print(e);
         }
     } }

Any ideas? Sometimes the not connected message is written even if I don’t send a message.

Greets