Comment #3 on issue 6 by
dark.cri...@gmail.com: Реализовать реакцию на
обрыв соединения
http://code.google.com/p/caffeineim/issues/detail?id=6
ru.caffeineim.protocols.icq.core.OscarClient
+ public synchronized boolean getRuning() { return running; }
ru.caffeineim.protocols.icq.core.OscarPingHandler
+ try {
while(connection.getClient().getRuning()) {
if (connection.isAuthorized()) {
//System.err.println("ping...");
connection.sendFlap(new KeepAlive());
}
Thread.sleep(interval);
}
} catch (InterruptedException e) { e.printStackTrace(); }
И уже в главном классе, написать например так:
public void onLogout(Exception exception) {
try {
Logger.writelnErr("ReConnect #0\nReconnect on 60
secounds...");
Thread.sleep(60000);
this.reConnect();
} catch (Exception ex) {
try {
Logger.writelnErr("ReConnect
#1\n"+ex.getMessage()+"\nReconnect on 60
secounds...");
Thread.sleep(60000);
this.reConnect();
} catch (Exception ex1) {
Logger.writelnErr(ex1.getMessage()+"\nLogged
out (possibly due to error)"); ex1.printStackTrace();
System.out.println("Logged out
(possibly due to error)"); }
} Logger.writelnErr("ReConnect #X");
}
public void reConnect() {
try {
Logger.writelnErr("Init reConnect");
try {
this.connection.getClient().disconnect();
} catch (Exception ex0) { Logger.writelnErr(ex0.getMessage()); }
Thread.sleep(4000);
Logger.writelnErr("Stop all listners... wait 60 secounds...");
this.connection.removeOurStatusListener(this);
this.connection.removeUserStatusListener(this);
this.connection.removeMessagingListener(this);
this.connection.close();
Thread.sleep(60000);
this.connection = null;
Logger.writelnErr("Login to:"+SERVER+":"+PORT+"\nUIN: "+UIN);
this.connection = new OscarConnection(SERVER, PORT, UIN,
PASSWORD, null);
connection.addMessagingListener(this);
connection.addUserStatusListener(this);
connection.addOurStatusListener(this);
connection.connect();
} catch (Exception ex) { Logger.writelnErr(ex.getMessage()); }
}