android - smack 4.2.0 错误 : IN AAAA yielded an error response NX_DOMAIN

标签 android xmpp chat smack

我启动 openFire 并用 spark 测试它一切正常但是当我尝试在 android studio 中连接 smack 4.2.0 时我得到了这个错误:

Ljavax/命名/目录/InitialDirContext;

我的依赖是这样的:

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"

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

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"

我得到了这个错误:

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

当我尝试 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();  

最佳答案

您遇到的错误是由于您的 XMPP 服务器寻址不完整造成的。

想象一下这个场景:

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

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

"davood@localhost" and "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!");


            }

关于android - smack 4.2.0 错误 : IN AAAA yielded an error response NX_DOMAIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43143359/

相关文章:

android - 如何使用 XMPP 在 android 中执行群聊

chat - 如何构建gmail聊天机器人?

mysql - 我需要3秒的间隔来执行每个mysql_query

android - TextView不靠右

android - 设备的Android版本与应用中指定的版本之间的关系

android - 创建用户时 XMPP jid-malformed(400) 错误 Android

ios - 实现ios聊天(如whatsapp): websocket?

java - 使用实时数据和改造 Android 时图像无法正确显示

java - Android - 将位图分配给 ImageView 会更改大小

asp.net - 我可以将任何 XMPP 客户端与 ASP.NET 一起使用吗?