smack 4.2.0 错误:IN AAAA 产生错误响应 NX_DOMAIN
Error on smack 4.2.0 : IN AAAA yielded an error response NX_DOMAIN
我启动 openFire 并用 spark 测试一切正常,但是当我尝试在 android studio 中连接 smack 4.2.0 时,我收到了这个错误:
Ljavax/naming/directory/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"
删除时:
"compile 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!");
}
请检查:
https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide
在以前的 Smack 版本中,ConnectionConfiguration.setHost(String) 可用于设置 XMPP 服务的主机 IP 地址。由于添加了 DNSSEC 支持,这不再可能。您必须改用新的连接配置 ConnectionConfiguration.setHostAddress(InetAddress)。
你也可以检查这个。
我在 Kotlin 中遇到了与 Xmpp 连接有些相同的问题,我根据@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");
}
}
我启动 openFire 并用 spark 测试一切正常,但是当我尝试在 android studio 中连接 smack 4.2.0 时,我收到了这个错误:
Ljavax/naming/directory/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"
删除时: "compile 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!");
}
请检查: https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide
在以前的 Smack 版本中,ConnectionConfiguration.setHost(String) 可用于设置 XMPP 服务的主机 IP 地址。由于添加了 DNSSEC 支持,这不再可能。您必须改用新的连接配置 ConnectionConfiguration.setHostAddress(InetAddress)。
你也可以检查这个。
我在 Kotlin 中遇到了与 Xmpp 连接有些相同的问题,我根据@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");
}
}