smack 4.2.0出错:在AAAA中产生了错误响应NX_DOMAIN

时间:2017-03-31 14:36:49

标签: android xmpp chat smack

我启动openFire并使用spark测试它一切正常但是当我尝试在android studio中连接smack 4.2.0时出现此错误:

Ljavax /命名/目录/ InitialDirContext;

我的依赖是这样的:

  

编译“org.igniterealtime.smack:smack-java7:4.2.0”编译   “org.igniterealtime.smack:smack-tcp:4.2.0”编译   “org.igniterealtime.smack:smack-im:4.2.0”编译   “org.igniterealtime.smack:smack-extensions:4.2.0”编译   “org.igniterealtime.smack:smack-android-extensions:4.2.0”编译   “org.igniterealtime.smack:咂嘴-炉腹:4.2.0”

删除时: “编译org.igniterealtime.smack:smack-java7:4.2.0” 从依赖项中添加: 编译“org.igniterealtime.smack:smack-android:4.2.0” 我的依赖关系变成这样:

  

编译'com.android.support:appcompat-v7:24.0.0'编译   “org.igniterealtime.smack:smack-android:4.2.0”编译   “org.igniterealtime.smack:smack-tcp:4.2.0”编译   “org.igniterealtime.smack:smack-im:4.2.0”编译   “org.igniterealtime.smack:smack-extensions:4.2.0”编译   “org.igniterealtime.smack:smack-android-extensions:4.2.0”编译   “org.igniterealtime.smack:咂嘴-炉腹:4.2.0”

我收到此错误:

  

org.jivesoftware.smack.SmackException $ ConnectionException:The   以下地址失败:'192.168.209.2:5222'失败,原因是:   de.measite.minidns.hla.ResolutionUnsuccessfulException:要求   192.168.209.2。 IN A产生错误响应NX_DOMAIN,'192.168.209.2:5222'失败,原因是:   de.measite.minidns.hla.ResolutionUnsuccessfulException:要求   192.168.209.2。在AAAA中产生了错误响应NX_DOMAIN

当我尝试使用conn.connect()时出现错误的代码部分是这样的:

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

3 个答案:

答案 0 :(得分:18)

您遇到的错误源于您的XMPP服务器的不完整寻址。

想象一下这种情况:

  

我的ejabberd服务器正在这个地址上运行:192.168.209.2 #ejabberd   服务器

有一个名为" localhost"的xmpp域名。有两个JID,

  

" davood @本地"和#34; sadegh @ localhost"

在smack中,我想与我的用户进行身份验证,说" davood @ localhost"。 然后我这样做:

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


            }

答案 1 :(得分:8)

请检查: https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide

在以前版本的Smack中,ConnectionConfiguration.setHost(String)可用于设置XMPP服务的主机IP地址。由于添加了DNSSEC支持,这已不再可能。您必须使用新的连接配置ConnectionConfiguration.setHostAddress(InetAddress)。

您也可以查看。

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

答案 2 :(得分:0)

我在 Kotlin 中使用 Xmpp Connection 遇到了一些相同的问题,我根据 @davood-falahati 的回答实施了解决方案,并做了一些更改,对我来说效果很好:

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

        }
    }