1
我想连接到使用smack API的openfire服务器,我无法这样做。无法连接到Openfire服务器
下面是代码:
public class Tests{
public static void main(String[] args) {
System.out.println("Starting IM client");
// gtalk requires this or your messages bounce back as errors
ConnectionConfiguration connConfig = new ConnectionConfiguration("localhost", 5222);
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
System.out.println("Connected to " + connection.getHost());
} catch (XMPPException ex) {
//ex.printStackTrace();
System.out.println("Failed to connect to " + connection.getHost());
System.exit(1);
}
try {
connection.login("[email protected]", "setup1");
System.out.println("Logged in as " + connection.getUser());
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
} catch (XMPPException ex) {
//ex.printStackTrace();
System.out.println("Failed to log in as " + connection.getUser());
System.exit(1);
}
connection.disconnect();
}
}
以下是输出:
Starting IM client
Connected to localhost
Failed to log in as null
似乎连接到服务器,但无法登录
k ...这工作。所以如果服务器是在实际域中,那么我应该使用[email protected]从客户端设备登录,对吧? – frewper 2012-03-19 10:16:36
我认为你总是可以用用户名登录,但[email protected]也应该可以工作。 – Maggie 2012-03-19 10:23:38
在XMPP界面上,您总是需要一个域。我不知道这个API是否需要它,但我会虚心地暗示,为了一致性,无论如何都使用域是个好主意。 – 2012-03-19 10:51:43