尝试从 aSmack Android 客户端连接到 XMPP 服务器时出现 ConnectionException [英] ConnectionException when trying to connect to XMPP server from aSmack Android client

查看:41
本文介绍了尝试从 aSmack Android 客户端连接到 XMPP 服务器时出现 ConnectionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个小时以来,我一直在尝试从我的 aSmack Android 客户端连接到我的(本地托管的)Openfire XMPP 服务器,但它仍然无法正常工作.

我得到一个 org.jivesoftware.smack.SmackException$ConnectionException 就是这样.

代码:

public class MainActivity extends Activity {@覆盖protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);SmackAndroid.init(getApplicationContext());连接();}私人布尔连接(){XMPPConnection connection = new XMPPTCPConnection(HOST);尝试{连接.connect();connection.login("user", "user");}catch(异常 e){e.printStackTrace();}返回真;}

服务器已启动并正在运行.

主机是我的服务器名,也试过我的主机名,试过不同的端口...还尝试从另一个线程启动 connect() 方法.尝试使用登录或匿名连接,但在此之前抛出异常,在行:connection.connect();

非常感谢任何帮助.

解决方案

我得到一个 org.jivesoftware.smack.SmackException$ConnectionException 和就是这样.

不,不是.如果您查看 javadocConnectionException:

<块引用>

如果 Smack 无法连接到所有,则抛出 ConnectionException给定 XMPP 服务的主机.可以使用以下命令检索失败的主机getFailedAddresses(),这将导致异常连接失败设置和检索HostAddress.getException().

因此调用 ConnectionException.getFailedAddresses() 来检索列表并使用 HostAddress.getException() 检查导致 Smack 无法连接到主机的原因.>

I have been trying to connect to my (locally hosted) Openfire XMPP server from my aSmack Android client for hours now, and it's still not working.

I get a org.jivesoftware.smack.SmackException$ConnectionException and that's it.

Code:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SmackAndroid.init(getApplicationContext());
    connect();
}

private boolean connect(){
    XMPPConnection connection = new XMPPTCPConnection(HOST);
    try{
        connection.connect();
        connection.login("user", "user");
    }catch (Exception e){
        e.printStackTrace();
    }
    return true;
}

Server is up and running.

Host is my server name, tried my host name too, tried different ports... Also tried to launch the connect() method from another thread. Tried to use a login or anonymous connection, but Exception is thrown before even that, at line: connection.connect();

Any help highly appreciated.

解决方案

I get a org.jivesoftware.smack.SmackException$ConnectionException and that's it.

No, it's not. If you look at the javadoc for ConnectionException:

ConnectionException is thrown if Smack is unable to connect to all hosts of a given XMPP service. The failed hosts can be retrieved with getFailedAddresses(), which will have the exception causing the connection failure set and retrievable with HostAddress.getException().

So call ConnectionException.getFailedAddresses() to retrieve the list and check with HostAddress.getException() what caused Smack to be unable to connect to the host.

这篇关于尝试从 aSmack Android 客户端连接到 XMPP 服务器时出现 ConnectionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆