I use the Smack server and Openfire for the chat client, everything works fine, like chat, sends an invitation to a new user addition, receives a list of available users, etc. I have no clue what to do if the connection is in the sticky service, and I added a connection listener to the connection and the disconnected connection, say, for "Internet connection"
I am using the code below for connectlistener.
connection.addConnectionListener(new ConnectionListener() { @Override public void reconnectionSuccessful() { Log.i("","Successfully reconnected to the XMPP server."); } @Override public void reconnectionFailed(Exception arg0) { Log.i("","Failed to reconnect to the XMPP server."); } @Override public void reconnectingIn(int seconds) { Log.i("","Reconnecting in " + seconds + " seconds."); } @Override public void connectionClosedOnError(Exception arg0) { Log.i("","Connection to XMPP server was lost."); Log.v("ONMESSAGE", "Error was " + arg0.toString() + "and Now connecting"); } @Override public void connectionClosed() { Log.i("","XMPP connection was closed."); } });
So, I thought about adding two lines of code to connectionClosedOnError () i.e.
connection.disconnect(new Presence(Presence.Type.unavailable)); //code for connection(new one)
Which gives me some time after the error
- No response from server.
- Not connected to the server.
- conflict error
Now I investigated the problem and found that there is still a connection when I try to reconnect using the same resource so that I get errors. My question is how to make a reconnection and what is the correct procedure for doing this?
I know how to resolve the "XMPP" thread of the problem: error (conflict) ", since I can provide the String to login () method as the third parameter, and this fixes the problem.
This is not my main problem that I want to know about the reconnection procedure. I tried to log into the system in all methods, and it is rather surprising that there is no order of the called methods.