aSmack 4.0.* XMPPTCPConnection can't connect t

2019-05-30 08:28发布

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 ?

2条回答
聊天终结者
2楼-- · 2019-05-30 09:21

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);
查看更多
Viruses.
3楼-- · 2019-05-30 09:34

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();
}
查看更多
登录 后发表回答