- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我启动 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/
我启动 openFire 并用 spark 测试它一切正常但是当我尝试在 android studio 中连接 smack 4.2.0 时我得到了这个错误: Ljavax/命名/目录/InitialD
在我将 smack 升级到 4.2.0 后,我遇到了连接问题。 The following addresses failed: 'xxxx:5222' failed because: de.measi
我是一名优秀的程序员,十分优秀!