在AAAA中产生了错误响应NX

在AAAA中产生了错误响应NX

本文介绍了smack 4.2.0上的错误:在AAAA中产生了错误响应NX_DOMAIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

Ljavax/naming/directory/InitialDirContext;

我的依赖项是这样:

删除时:编译org.igniterealtime.smack:smack-java7:4.2.0"从依赖项,并添加以下内容:编译"org.igniterealtime.smack:smack-android: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:

我收到此错误:

当我尝试conn.connect()时出错的代码部分是:

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

推荐答案

您遇到的错误是由于XMPP服务器地址不完整引起的.

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

想象一下这种情况:

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

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

我想通过用户身份验证,说"davood @ 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!");


            }

这篇关于smack 4.2.0上的错误:在AAAA中产生了错误响应NX_DOMAIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 21:26