Fix Auto Login after Disconnect
Status: Alpha
Brought to you by:
javakiddy
Hi everybody,
I have just used jYMSG to create my app. Now I want to do this task: Auto Login after disconnect suddenly. I tried a connectionClosed event in SessionListener, but it only work fine when I logout completely. Now I want to implement this task follow:
while (connectYahooServer fail) {
Count from 10 to 1;
Check connectYahooServer;
}
//connectYahooServer success
autoLogin again;
Please help me. Thank you.
Hi there,
I've found a solution to fix this problem but I don't reach to jYMSG package. it's simple using a mathematic. In GUI class's main function, you should do this task follow:
public static void main(String args[]) {
YM ym = new YM(); //YM is name of GUI class
boolean flag = false;
String host = "scsc.msg.yahoo.com"; //Yahoo server
int port = 5050;
ym.setVisible(true);
//Check connection to Yahoo Server every 10s/once
while (true){
Socket socket = null;
try {
socket = new Socket(host,port);
}catch (IOException io){}
//If connection failed
if (socket == null){
flag = true;
ym.logout(); //logout is method in YM class
int timeout = 10;
for (int i=timeout;i>0;i--){
try {
Thread.sleep(1000);
}catch (InterruptedException ie){}
System.out.println("Reconnect after "+i+"s");
}
}
//If connection successed
else {
if (flafg == true) {
ym.login(); //login is method in YM class
flag = false;
}
}
try {
Thread.sleep(1000*10);
}catch (InterruptedException ie){}
} //end while
} //end main
This demo which I've used is YahooClient. (Sorry, I forgot author's name ^^!)