11

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();  
4
  • remove .setXmppDomain("192.168.1.3") this method and setServiceName() and provide user name and password while your login to the xmpp server Commented Mar 31, 2017 at 17:50
  • this works in smack 4.1.6 and I'm using currently it works for me thanks Commented Mar 31, 2017 at 18:11
  • yes its work in above 4.2.0 versions currently i'm using 4.1.9 and it's working but i need the new version 4.2.0
    – sadegh
    Commented Apr 1, 2017 at 6:57
  • use .setHostAddress(InetAddress.getByName(DOMAIN_IP_ADDRESS)) instead of .setHost(HOST) Commented Jan 29, 2018 at 12:43

3 Answers 3

23

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!");


            }
2
  • I have the same issue to connect emulator to ejabbred server. I followed your snippet code to set host address as 'InetAddress addr = InetAddress.getByName("10.0.2.2")'; but it throws this exception: The following addresses failed: 'null:5222'. Commented Apr 3, 2018 at 11:57
  • Iranian developers are always the best Commented Jun 9, 2021 at 17:36
9

Please check : https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide

In previous versions of Smack, ConnectionConfiguration.setHost(String) could be used to set the XMPP service's host IP address. This is no longer possible due to the added DNSSEC support. You have to use the new connection configuration ConnectionConfiguration.setHostAddress(InetAddress) instead.

You can check this also.

failed because: de.measite.minidns.hla.ResolutionUnsuccessfulException: Asking for xxxx. IN AAAA yielded an error response NX_DOMAIN

0

I had somewhat same issue with Xmpp Connection in Kotlin and I implemented the solution based on @davood-falahati 's answer with some changes, it worked fine for me:

private fun initializeXmppConnection(){
        val addr: InetAddress = InetAddress.getByName("90.182.109.19")
        val verifier: HostnameVerifier = HostnameVerifier { s, sslSession -> false }
        val serviceName: DomainBareJid = JidCreate.domainBareFrom("im.mydomain.ir")
        val config: XMPPTCPConnectionConfiguration = XMPPTCPConnectionConfiguration.builder()
            .setHost("90.182.109.19")
            .setUsernameAndPassword("60b9d4d75943a","9yqx7heu6aok4g40so8s0w8oocow8w8")
            .setPort(80)
            .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
            .setXmppDomain(serviceName)
            .setHostnameVerifier(verifier)
            .setHostAddress(addr)
            .setSendPresence(true)
            .setCompressionEnabled(false)
            .setConnectTimeout(30_000)
            .build()

        val conn: AbstractXMPPConnection = XMPPTCPConnection(config)
        conn.connect();

        if(conn.isConnected())
            Log.d("msn","Connected");

        conn.login();

        if(conn1.isAuthenticated()){
            Log.d("msn","Authenticated");

        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.