I wrote a very simple test case and found out a bit more about the problem. isConnected works on my Windows machine (W2K, Java 1.4.2) but not on my G4 Laptop (OSX 10.3.1, Java 1.4.1).
Here is how I test:
Windows:
Run the test and disable the network connection. isConnected return false afterwards and connectionCloseOnError is invoked. Seems like everything works.
OSX:
Run the test and physically unplug the connection. isConnected still return true afterwards. I also waited for a few minutes to make sure that it isn’'t a timeout issue.
I don’‘t have a desktop OSX machine so I am not sure if it’'s machine dependent.
If it turns out to be a bug outside of smack and I can’'t fixed it, do you have a suggestion to work around this problem? Thanks.
Here is my simple test program (need to fill in the host, user, and password):
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
public class SmackTest {
public SmackTest() {
}
public static void main(String[] args) throws Exception{
String host = “server”;
String user = “username”;
String pass = “password”;
XMPPConnection connection = new XMPPConnection(host);
connection.login(user, pass);
ConnectionListener listener = new ConnectionListener(){
public void connectionClosed(){
System.out.println(“Connection close notified.”);
System.exit(0);
}
public void connectionClosedOnError(Exception e){
System.out.println(“Connection close on error.”);
System.out.println(e);
System.exit(0);
}
};
connection.addConnectionListener(listener);
while(true){
System.out.println("Connected " + connection.isConnected());
Thread.sleep(2000);
}
}
}