powered by Jive Software

Disconnection without error and no reconnection

Hi,

We have a smack implementation and we want it to stay connected to server forever. After days of running, we saw that it is disconnected. Looking at the logs, connection listeners connectionClosed() (not connectionClosedOnError) method is called. I looked at the source code and just found those lines:

else if (eventType == XmlPullParser.END_TAG) {

if (parser.getName().equals(“stream”)) {

// Disconnect the connection

connection.disconnect();

}

}

It looks like the server wants to end the connection if I understood correctly.

  1. Why the server wants to end the connection? Is there a reason that is sent when closing the stream tag? (gtalk server)

  2. So, I did not close the connection. Am I expected to implement reconnection logic in my connectionlistener’s connectionClosed method? I understand reconnection as “stay connected while server is available no matter what happens”.

Thanks for your help again.

You will need to implement reconnection logic. TCP/IP connections can be severed for many reasons and the best thing to try to do is reconnect in the case that the connection is lost.

Cheers,

Alex

Yes, TCP/IP connections can

be severed for many reasons, and Smack handles most of them when you set reconnectionEnabled(true)(I thought that all of them). In this case, I think the connection is not lost actually, server wants to close it because by sending a packet that closes the stream tag. So, this does not seem as a weird case. Correct me if I am wrong. Isn’t it good for all of us that Smack handles the reconnection logic upon receiving a stream close tag? Is there a reason for you for not doing that? If I have to, I have a few more questions:

  1. How can I recreate the case that the server closes the stream tag?

  2. What is the best way to reconnect.

I think I have to wander aroud the smack source to answer 2.

Thanks for help.