【问题标题】:aSmack 4.0.* XMPPTCPConnection can't connect to OpenFire and Ejabbered (SmackException$NoResponseException)aSmack 4.0.* XMPPTCPConnection 无法连接到 OpenFire 和 Ejabbered (SmackException$NoResponseException)
【发布时间】:2024-01-02 13:17:01
【问题描述】:

我正在使用 asmack-android-8-source-4.0.6

当我尝试连接到服务器时,无论是 openFire 还是 Ejabbered,我都会收到此异常

org.jivesoftware.smack.SmackException$NoResponseException

这是我的代码:

        SmackAndroid.init(getApplicationContext());
        ConnectionConfiguration conConfig = new ConnectionConfiguration(HOST, PORT);
        conConfig.setDebuggerEnabled(true);

        connection = new XMPPTCPConnection(conConfig);
        try {
            connection.connect();
            Log.i("AppName", "CONNECTED TO " + connection.getHost());
        }

当我打电话时

connection.connect();

我得到了这个例外:

org.jivesoftware.smack.SmackException$NoResponseException

请注意,我在 asmack-android-19-0.8.10 上尝试过相同的代码,并且效果很好

我想问题出在

XMPPTCP连接

因为在 asmack-android-19-0.8.10 我使用

XMPP连接

有什么帮助吗?

【问题讨论】:

  • 始终发布异常的完整堆栈跟踪。还将 SmackConfiguration.DEBUG 设置为 true 并向我们显示输出。
  • @Flow 我在下面发布了答案:community.igniterealtime.org/message/240285#240285
  • @Flow 感谢您的帮助!!! :) 我读过你的很多帖子和 cmets :)

标签: android xmpp ejabberd smack asmack


【解决方案1】:

我发现我所做的只是添加这一行:

ConnectionConfiguration.setSecurityMode(SecurityMode.disabled);

我已成功连接到服务器

这是我最后的配置:

ConnectionConfiguration ConnectionConfiguration =  new ConnectionConfiguration(HOST, PORT);
ConnectionConfiguration.setDebuggerEnabled(true);
ConnectionConfiguration.setSecurityMode(SecurityMode.disabled);

【讨论】:

  • 我也面临同样的问题。我也禁用了安全模式,我正在使用这个code 连接到 xmpp,我得到了exception,你能告诉任何解决方案吗?
  • 你得到了什么异常?
  • @user987760 您是否曾使用 xmpp 和 asmack 进行文件共享。如果是,请帮助解决这个问题issue
  • @AndroidRockss 我没有使用 xmpp 文件共享,而是使用 http 上传/下载媒体,我通过自定义 PackageExtention 发送 url
【解决方案2】:

试试这个:

public void connect() 
{

    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            SmackAndroid.init(getApplicationContext());

            ConnectionConfiguration conConfig = new ConnectionConfiguration(HOST, PORT);
            conConfig.setDebuggerEnabled(true);
            conConfig.setSecurityMode(SecurityMode.disabled);
            connection = new XMPPTCPConnection(conConfig);
            try {
                connection.connect();
                connection.login("unm", "pswd");
                Presence presence = new Presence(Presence.Type.available);
                connection.sendPacket(presence);
                setConnection(connection);

            } catch (XMPPException e) {
                e.printStackTrace();
            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    t.start();
}

【讨论】:

  • 你能解释一下你的答案吗?它不够清楚,无法理解
  • 我的代码是关于使用 asmack-android-8-4.0.6 库的连接和登录。