Hello Friend,
This is the code I m using :
ConnectionConfiguration cc = new ConnectionConfiguration(this.config.getHost(),this.config.getPort());
System.out.println(“Reached in DeviceSignalingChannel init()”);
while (true) {
XMPPConnection conn = new XMPPConnection(cc);
try {
conn.connect();
this.acceptor.addConnection(conn);
conn.login(this.config.getUserName(), this.config.getPassword());
System.out.println(“Connected”);
//Thread.sleep(50000);
this.connection = conn;
//break;
} catch (Exception ex) {
System.out.println("After connected "+ex );
XMPPConnection tmp = new XMPPConnection(cc);
try {
tmp.connect();
System.out.println(“Redirected”);
AccountManager am = tmp.getAccountManager();
System.out.println(“1”);
String password = this.createNewPassword(this.config.getUserName());
System.out.println("check here " +password);
try {
am.createAccount(this.config.getUserName(), password);
tmp.login(this.config.getUserName(), password);
} catch(Exception e) {
e.printStackTrace();
System.out.println("why " +e);
}
System.out.println(“work done”);
//this.config.storePassword(password);
} catch (Exception e) {
System.out.println(“smack exception”);
throw new SignalingException(e);
} finally {
System.out.println(“1st disconnect”);
tmp.disconnect();
}
} finally {
if (conn != null && !conn.isAuthenticated()) {
System.out.println(“2nd disconnect”);
conn.disconnect();
}
}
}
When I run the above program, it runs, connectes to the XMPP server , logs in successfully and immediately disconnects.
if I use Thread.sleep(milliseconds) , then it will wait for those miliseconds, but i don’t want that.
What I want is : it should be connected for endless time unless I call the XMPPConnection’s disconnect() method.
I tried it putting in while(true) loop, but it didn’t work
Please help me.
Thanks