powered by Jive Software

Reconnection and login()

Hi,

I’m using the ReconnectionManager and I don’t understand why I’m automatically authenticated when I’m reconnected successfully. I’ve looked at the source of the ReconnectionManager and it seems that it only connects to the server and doesn’t care of the authentication.

In my application, I want to join a room when I’m reconnected. So I’ve just implemented a ConnectionListener which joins the room when a reconnection successful event is caught.

But before to be able to join a room, I have to wait to be authenticated. I could do the authentication by myself, but it seems that it’s done automatically… I just don’t know by who it’s done…?

Thanks,

phil

It says so somewhere (I can’t find the particular site right now) that when the connection is lost unexpectedly, a reconnect will use the credentials from the previous established connection.

In your ConnectionListener.reconnectionSuccessful() method, you could set a variable that lets you know what is going on.

You’re right, it’s in the doc of the XMPPConnection.connect() method:

http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/ smack/XMPPConnection.html#connect()

Simply…

Thanks,

phil

One thing that puzzles me is that in the reconenctionSuccessful() callback, I’m connected but not yet authenticated? At least thats the way I read the code.

Since I want to do a few things after beeing fully reconnected, I thought I should do that in this callback, but it’s not working since I’m not logged in yet (Server barfs and shuts down the connection).

By reading the code, I see that after returning from the reconnectionSuccessful, the ReconnectManager() continues and eventually authenticates me, but I never get a callback AFTER beeing authenticated, which is what I need!

Is there any way around this? I need a way of sending some stuff immediately after beeing reconnected/logged-in.

If I login myself in reconnectionSuccesful(), Smack itsef throws an Exception later “Already logged in to server”.

Am I missing something here??

Thanks

Peter

Hi,

the login problem comes from the connect method:

http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/ smack/XMPPConnection.html#connect()

As you can read, if you connect and log in and then disconnect and re-connect, you will be logged in automatically. That’s what the reconnection mechanism does, it calls connect() , so when you get reconnected, you’re gonna be re-authenticated.

The problem is that when the reconnectionSuccessfull() callback is called, you’re not yet re-authenticated, so you cannot authenticate by yourself, else you will get the exception you speak about since there will be 2 trires to log in (yours and the one caused by the reconnection mechanism) .

I also wanted to do something after being reconnected/reauthenticated so I decided to start a thread in the reconnection successful callback. This thread first make a loop like:

while (!connection.isAuthenticated()) {

sleep(100);

}

and then I do what I want…

It’s not really clean but it works. The best I think would be that the reconnection successfull callback would be called once we re-authenticated and not once we only reconnect.

Hope it was clear, because I’m really tired

phil

Hello,

Yes I was thinking along those lines myself, but I was hoping for a cleaner solution…

Thanks anyway, I will do a similiar solution,but it would surely be a lot easier if Smack just send us a reloginSuccesful() too!

Thanks

Peter