8

I am using Smack and Openfire server for a chat client, all things working well like chat, sending an invitation for a new addition of user, getting list of available users etc. I don't have a clue what to do if the connection is in a Sticky Service and I added a connection listener to the connection and connection disconnected, let's say for "Internet Connection"

I am using the below code for the connectionlistener.

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 of 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 following error

  1. No Response from Server.
  2. Not connected to server.
  3. conflict error

Now I researched on the issue and found there is still connection when I try to reconnect using the same resource so I got the errors. My question is how to do reconnection and what is the correct procedure for that?

I know how to resolve the issue "XMPP “stream:error (conflict)” as I can provide a String to login() method as a third parameter and it resolves the issue.

That is not my main concern, what I want to know the procedure of reconnection. I tried logging in all methods and it's quite amazing that there are no order of methods being called.

halfer
  • 19,824
  • 17
  • 99
  • 186
Saty
  • 2,563
  • 3
  • 37
  • 88
  • possible duplicate of [XMPP "stream:error (conflict)" on login with (a)Smack](http://stackoverflow.com/questions/16077100/xmpp-streamerror-conflict-on-login-with-asmack) – Flow Jul 29 '14 at 19:14
  • 2
    Yeah @Flow thats true however I came here after reading that post too...I did not find much of a solution there. My question is what is the correct procedure of reconnection cause I tried to log methods in connectionlistener and I found out that if I disconnect the internet, it first call "connectionClosedOnError()", then nothing happens..so I want to ask is this the correct behavior and what are other methods for? and it does not keep calling methods in listener. Please give me some insight. – Saty Jul 30 '14 at 04:38
  • Hello , @Saty I face same error , You find out correct way ? – Joseph Mekwan Nov 05 '15 at 11:05
  • I am sorry joseph...I ad to drop that project cause I could not complete that project in time because of the same issue. Then I never used it – Saty Nov 05 '15 at 11:36

0 Answers0