gpt4 book ai didi

java - 无法连接到 Openfire 服务器

转载 作者:行者123 更新时间:2023-11-30 04:51:16 27 4
gpt4 key购买 nike

我正在尝试使用 smack API 连接到 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("test@example.com", "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

似乎可以连接到服务器,但无法登录。

最佳答案

connection.login("test@example.com", "setup1");

如果您的服务器在本地主机上启动,您绝对不应该登录 example.com 域。尝试一下:

 connection.login("test", "setup1");

但请记住,为了能够登录,您需要拥有有效的用户名和密码。这意味着您必须在服务器上创建用户“test”,密码为“setup1”。

关于java - 无法连接到 Openfire 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9768202/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com