aSmack 4.0。* XMPPTCPConnection无法连接到OpenFire和Ejabbered(SmackException $ NoResponseException)

时间:2015-01-15 09:48:43

标签: android xmpp ejabberd smack asmack

我正在使用 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 上尝试了相同的代码,它运作正常

我猜问题是

  

XMPPTCPConnection

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

  

XMPPConnection

任何帮助?

2 个答案:

答案 0 :(得分:2)

我发现问题是我所做的就是添加这一行:

ConnectionConfiguration.setSecurityMode(SecurityMode.disabled);

我已成功连接到服务器

这是我最后的配置:

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

答案 1 :(得分:0)

试试这个:

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();
}