gpt4 book ai didi

android - 无法连接到本地 openfire XMPP 服务器

转载 作者:行者123 更新时间:2023-11-29 20:58:42 27 4
gpt4 key购买 nike

我正在开发一个 android 应用程序,我一直在尝试连接到本地安装的 openfire 服务器。服务器已启动并正在运行,但当我尝试在我的手机上运行该应用程序时,它没有连接到服务器。

代码:

public class ChatService extends Service implements ConnectionListener {
private static Configuration configuration;
private static final String TAG = ChatService.class.getSimpleName();
public static void setupConnection(){
configuration = new Configuration();
final ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(configuration.getHost(), configuration.getPort(), configuration.getServiceName());
Log.d(TAG, "Host: " + configuration.getHost());
Log.d(TAG, "Port: " + configuration.getPort());
Log.d(TAG, "Service name: " + configuration.getServiceName());
Thread t = new Thread(new Runnable() {

@Override
public void run() {
configuration.setDebuggerEnabled(true);
XMPPConnection connection = new XMPPTCPConnection(connectionConfiguration);

try {
connection.connect();
if(connection.isConnected()){
Log.d(TAG, "Connected to server");
}
} catch (SmackException.ConnectionException e) {
for (int i = 0; i < e.getFailedAddresses().size(); i++) {
HostAddress element = e.getFailedAddresses().get(i);
Log.e("ERROR", element.getErrorMessage().toString());
}
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
t.start();
}

在 logcat 中,我收到 SmackException$ConnectException。

日志:

11-10 00:48:20.400  18449-18860/com.example.puneet.chat E/ERROR﹕ localhost:5222 Exception: failed to connect to localhost/127.0.0.1 (port 5222): connect failed: ECONNREFUSED (Connection refused)
11-10 00:48:20.408 18449-18860/com.example.puneet.chat W/System.err﹕ org.jivesoftware.smack.SmackException$ConnectionException
11-10 00:48:20.408 18449-18860/com.example.puneet.chat W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:433)
11-10 00:48:20.408 18449-18860/com.example.puneet.chat W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:808)
11-10 00:48:20.408 18449-18860/com.example.puneet.chat W/System.err﹕ at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:396)
11-10 00:48:20.408 18449-18860/com.example.puneet.chat W/System.err﹕ at XMPPConnection.ChatService$1.run(ChatService.java:45)
11-10 00:48:20.408 18449-18860/com.example.puneet.chat W/System.err﹕ at java.lang.Thread.run(Thread.java:856)

如果有人能帮助我理解为什么会出现此异常以及出了什么问题,我将不胜感激

最佳答案

设置configuration.host为

http://127.0.0.1:5222

然后尝试

如果还是有问题,到Openfire > server > server settings > client connections 然后检查有SSL (generally 5223) 的端口号>启用 SSL 并使用具有 5223 端口 号的主机。

http://127.0.0.1:5223

关于android - 无法连接到本地 openfire XMPP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26837628/

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