Very simple smack code doesn't work

I have Openfire 3.9.3 here. I have this Java code:

public class Main {

public static void main(String[] args) throws IOException, SmackException, XMPPException, InterruptedException {

ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(“http://localhost”, 5222);

XMPPConnection connection = new XMPPTCPConnection(connectionConfiguration);

connection.connect();

connection.login(“mhamdy”, “password”);

Presence presence = new Presence(Presence.Type.unavailable);

presence.setStatus(“Coding”);

connection.sendPacket(presence);

Thread.sleep(1000);

}

}

It’s raising this exception (at connection.connect() line ):

Exception in thread “main” org.jivesoftware.smack.SmackException$ConnectionException

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:436)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:811)

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

at Main.main(Main.java:15)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

What I’m doing wrong?. I tried just “localhost” and “http://localhost” and “127.0.0.1” and others. The server is running and I browse the admin just fine.

Please look at the javadoc of ConnectionException.

Thanks for the help, but that wasn’t helpful to me. I looked at the javadoc but I don’t know what to do with that.

In any case, I changed to configuration to **new ConnectionConfiguration(“localhost”, 5223); **and now I get:

Exception in thread “main” org.jivesoftware.smack.SmackException$NoResponseException

at org.jivesoftware.smack.XMPPConnection.throwConnectionExceptionOrNoResponse(XMPP Connection.java:548)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.throwConnectionExceptionOrNoRespon se(XMPPTCPConnection.java:867)

at org.jivesoftware.smack.tcp.PacketReader.startup(PacketReader.java:113)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.j ava:482)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPC onnection.java:440)

at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:811)

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

at Main.main(Main.java:15)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

A telnet at localhost and ports 5222, 5223 also seem to work. So there’s a problem on the code side.