How do you guys handle network connection issue in Smack?

Hello everyone,

I am new to Smack and XMPP in general. I wrote a very simple program to connect to a openfire server and send messages to another user. Everything worked fine. But I run into an issue while testing this program.

  1. I connect to the server and send a message successfully.

  2. I unpluged my network cable and send another message and expecting the “XMPPConnection.isConnected()” method to return false

**However, the XMPPConnection.isConnected() still returns true. **

I realized that there is the "ConnectionListener“ I can use. But the ConnectionListener.connectionClosedOnError()is not trigger immediately after a message is sent. It takes about 10 seconds for the ConnectionListener to receive an error on connection lost.

Does anyone know the best way to check connection error? (Maybe try to establish a network connection like this: http://stackoverflow.com/questions/1139547/detect-internet-connection-using-java before sending every message?)

Thanks!