Problem with ConnectionListener

hello,

I add ConnectionListener like this :

ConnectionListener cn = new ConnectionListener(){

public void connectionClosedOnError(Exception e){

System.out.println("Error "+e.getLocalizedMessage());

try{

reconnect(5, userr, pass,5);

} catch(InterruptedException ie){

for(int i = 0; i < vector.size(); i++){

vector.elementAt(i).errorNotification(getName(), "Interrupted: "

  • getMessageForCode(e.toString()));

}

}

}

public void connectionClosed(){

System.out.println(“closed”);

}

};

oCon.addConnectionListener(cn);

and I still have exceptions like java.net.SocketException: Connection reset

Am I doing something wrong?

Help

Yes that’'s wrong

ConnectionListener is a java interface, it is not newed, it is implemented by your object.

example snippet

public class receiver implements ConnectionListener, PacketListener

{

private XMPPConnection xmppCon; // The connection to the XMPP server

private String jabberServer = “sdooley”;

private String jabberUser = “receiver”;

private String jabberPassword = “receiver”;

private int msgnum = 0;

public receiver ()

{

try

{

System.out.println ("Connecting to server: " + this.jabberServer);

this.xmppCon = new XMPPConnection (this.jabberServer);

this.xmppCon.addConnectionListener (this);

}

// more code

}

// Implementation of ConnectionListener requires these methods

public void connectionClosed ()

{

System.out.println ("Closing? " + this.xmppCon.getUser () +

" connected: " + this.xmppCon.isConnected ());

}

}

By implementing an interface you provide the methods defined for the interface.

skip

I think you misunderstood his code (probably due to the absence of the -tags). He’'s creating an inner class using this construct.

thanks for understanding

And by the way I’'m a girl :stuck_out_tongue:

And still waiting for help

Selene,

What is your reconnect code doing?

Thanks,

Alex

I’‘m sorry for the gender misconception, it wasn’'t really obvious from your nick

What’'s the stack trace of the exception?