What is the proper strategy to re-connect a connection?

i am following the tutorials/guide that comes with the smack (3.2.0) download. it is nice for starters, but it doesn’t really talk about difficult cases. for example, what do we do when a connection has disconnected?

in my current code, what i do is keep 1 instance of Connection around. when that 1 connection has disconnected, i simply log in again. prior to the connection getting disconnected, i keep around all the Chat objects that have been created so i can reuse them to send/receive messages. i noticed that once the Connection has dropped, you can’t really use those Chat objects again. basically, if the user wants to send to a user, you’ll have to create a new Chat object from the new Connection.

this statement appears in the javadocs, “If a connected Connection gets disconnected abruptly then it will try to reconnect again.” what does this mean? does this mean that under any condition, if a Connection gets disconnnected it will attempt to re-connect? like if i disconnected the user manually from the web interface? because if that is the case, it has not proven to be true in my case.

lastly, what does this statement in the javadoc mean, “Connections can be reused between connections. This means that an Connection may be connected, disconnected and then connected again. Listeners of the Connection will be retained accross connections.” how do you reuse Connections between Connections? Do they mean Connections between Chats?

Your question is very valid, but the answer seeems to be far from easy. Spark uses Smack and has a log standing issue on disconnections/reconnections. We have spend some significant time on it and there is a master ticket SPARK-1224 for Spark regarding this. I can only encourage you to keep on working on it.