powered by Jive Software

NPE connecting to unresponsive server

Using smack 3.0.0 from the downloads page and the following code:

private static void connect(String host) {

try {

XMPPConnection conn = new XMPPConnection(new ConnectionConfiguration(host, 5222));

conn.connect();

conn.disconnect();

System.out.println("Successful: " + host);

} catch (XMPPException e) {

// TODO Auto-generated catch block

System.out.println("Unsuccessful: " + host);

e.printStackTrace();

}

}

I get an NPE connecting to an unresponsive host:

Connection failed. No response from server.:

at org.jivesoftware.smack.PacketReader.startup(PacketReader.java:164)

at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:875)

at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection. java:834)

at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1276)

at com.netg.connectiontest.JabberConnectionTest.connect(JabberConnectionTest.java: 12)

at com.netg.connectiontest.JabberConnectionTest.main(JabberConnectionTest.java:23)

Exception in thread “Smack Packet Reader (0)” java.lang.NullPointerException

at org.jivesoftware.smack.XMPPConnection.shutdown(XMPPConnection.java:564)

at org.jivesoftware.smack.PacketReader.notifyConnectionError(PacketReader.java:212 )

at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:375)

at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)

at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)