流水不争先,争的是滔滔不绝

Android使用smack4.2登录xmpp服务器(openfire)登录不上报错

openfire 云聊IM 3610℃

万事开头难!Android使用smack登录openfire常见错误

1.忘记在AndroidManifest.xml添加android.permission.INTERNET权限……

2.在UI主线程中执行连接openfire的操作……在Android中不可以在UI主线程中连接网络……

相关文章:Android使用smack4.3.3登录xmpp服务器(openfire)

在使用smack4.2登录openfire时一直报错,代码:

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

错误信息如下:

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

修改后:

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

本文转自:https://stackoverflow.com/questions/43143359/error-on-smack-4-2-0-in-aaaa-yielded-an-error-response-nx-domain

版权声明:部分文章、图片等内容为用户发布或互联网整理而来,仅供学习参考。如有侵犯您的版权,请联系我们,将立刻删除。
点击这里给我发消息