aSmack 4.0.* XMPPTCPConnection can't connect to OpenFire and Ejabbered (SmackException$NoResponseException)

房东的猫 提交于 2019-12-08 06:02:00

问题


I am using asmack-android-8-source-4.0.6

when i try to connect to the server whether it is openFire or Ejabbered i get this exception

org.jivesoftware.smack.SmackException$NoResponseException

here's my code:

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

when i call

connection.connect();

i get this exception :

org.jivesoftware.smack.SmackException$NoResponseException

note the i have tried the same code on asmack-android-19-0.8.10 and it works perfectly

i guess the issue is with the

XMPPTCPConnection

because in the asmack-android-19-0.8.10 i use

XMPPConnection

any help ?


回答1:


I have found the problem all i did is adding this line:

ConnectionConfiguration.setSecurityMode(SecurityMode.disabled);

and i was connected to server successfully

here's my configuration in the end :

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



回答2:


try this:

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


来源:https://stackoverflow.com/questions/27960686/asmack-4-0-xmpptcpconnection-cant-connect-to-openfire-and-ejabbered-smackexc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!