我总是收到此错误消息:org.jivesoftware.smack.SmackException $ ConnectionException:以下地址失败:
这是我的代码
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Runnable runnable = new Runnable() {
@Override
public void run() {
XMPPTCPConnectionConfiguration connectionConfiguration = null;
try {
InetAddress addr = InetAddress.getByName("10.0.2.2");
DomainBareJid serviceName = JidCreate.domainBareFrom("10.0.2.2");
connectionConfiguration = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("myusername", "mypassword")
.setXmppDomain(serviceName)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(5222)
.setHostAddress(addr)
.setDebuggerEnabled(true)
.build();
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}
AbstractXMPPConnection connection = null;
connection = new XMPPTCPConnection(connectionConfiguration);
try {
connection.connect().login();
} catch (XMPPException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Thread connectionThread = new Thread(runnable);
connectionThread.start();
}
});
我也尝试过公开的玉host和不同的端口,但是什么也没做。