Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

android - Error on smack 4.2.0 : IN AAAA yielded an error response NX_DOMAIN

i start openFire and test it with spark everything is ok but when i try to connect with smack 4.2.0 in android studio i got this error:

Ljavax/naming/directory/InitialDirContext;

and my dependencies is this:

compile "org.igniterealtime.smack:smack-java7:4.2.0" compile "org.igniterealtime.smack:smack-tcp:4.2.0" compile "org.igniterealtime.smack:smack-im:4.2.0" compile "org.igniterealtime.smack:smack-extensions:4.2.0" compile "org.igniterealtime.smack:smack-android-extensions:4.2.0" compile "org.igniterealtime.smack:smack-bosh:4.2.0"

when remove this : "compile org.igniterealtime.smack:smack-java7:4.2.0" from dependencies and add this: compile "org.igniterealtime.smack:smack-android:4.2.0" my dependencies become like this:

compile 'com.android.support:appcompat-v7:24.0.0' compile "org.igniterealtime.smack:smack-android:4.2.0" compile "org.igniterealtime.smack:smack-tcp:4.2.0" compile "org.igniterealtime.smack:smack-im:4.2.0" compile "org.igniterealtime.smack:smack-extensions:4.2.0" compile "org.igniterealtime.smack:smack-android-extensions:4.2.0" compile "org.igniterealtime.smack:smack-bosh:4.2.0"

I got This Error:

org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: '192.168.209.2:5222' failed because: de.measite.minidns.hla.ResolutionUnsuccessfulException: Asking for 192.168.209.2. IN A yielded an error response NX_DOMAIN, '192.168.209.2:5222' failed because: de.measite.minidns.hla.ResolutionUnsuccessfulException: Asking for 192.168.209.2. IN AAAA yielded an error response NX_DOMAIN

the part of code that make error when i try to conn.connect() is this:

XMPPTCPConnectionConfiguration config = null;  
            try {  
                config = XMPPTCPConnectionConfiguration.builder()  
                        .setUsernameAndPassword("admin", "thepass")  
                        .setXmppDomain("192.168.1.3")  
                        .setHost("192.168.209.2")  
                        .setPort(5222)  
                        .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)  
                        .build();  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
                AbstractXMPPConnection conn1 = new XMPPTCPConnection(config);  
                conn1.setReplyTimeout(60000);  
                conn1.setPacketReplyTimeout(60000);  
                conn1.connect();  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The error you have encountered is stemming from incomplete addressing of your XMPP server.

Imagine this scenario:

my ejabberd server is running on this address: 192.168.209.2 #ejabberd server

There is a xmpp domain named "localhost" There are two JIDs,

"davood@localhost" and "sadegh@localhost"

In smack, I want to authenticate with my user, say "davood@localhost". Then I do it as follow:

            InetAddress addr = InetAddress.getByName("192.168.209.2");
            HostnameVerifier verifier = new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return false;
                }
            };
            DomainBareJid serviceName = JidCreate.domainBareFrom("localhost");
            XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                    .setHost(server) # it will be resolved by setHostAddress method
                    .setUsernameAndPassword("davood","mypass")
                    .setPort(5222)
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                    .setXmppDomain(serviceName)
                    .setHostnameVerifier(verifier)
                    .setHostAddress(addr)
                    .setDebuggerEnabled(true)
                    .build();
            AbstractXMPPConnection conn1 = new XMPPTCPConnection(config);

            conn1.connect();

            if(conn1.isConnected()){
                Log.d("XMPP","Connected");
            }
            conn1.login();

            if(conn1.isAuthenticated()){
                Log.d("XMPP","Authenticated");
                EntityBareJid jid = JidCreate.entityBareFrom("sadegh@localhost");
                org.jivesoftware.smack.chat2.Chat chat = ChatManager.getInstanceFor(conn1).chatWith(jid);
                chat.send("Eureka, I am connected!");


            }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...