-1
我有点新的Android我试图建立一个聊天安卓应用 使用openfire作为服务器和sma 4.1.6 libs 现在我试图做一个基本的连接我正在关注的咂嘴文档Android的XMPP基本连接
XMPPTCPConnectionConfiguration.Builder conf = XMPPTCPConnectionConfiguration.builder();
conf.setUsernameAndPassword("user", "user");
conf.setResource("android");
conf.setServiceName("my_ip_adress");
conf.setHost("my_ip_adress");
conf.setPort(5222);
conf.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
AbstractXMPPConnection connection=new XMPPTCPConnection(conf.build());
try {
Log.e("CONNECTION====>", "try");
connection.connect();
Log.e("CONNECTION====>", "success");
connection.login();
Log.e("LOGIN====>", "success");
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
我在我的日志中获得此
E/CONNECTION====>: try
02-26 17:59:14.995 15119-15145/com.example.firas.simplexmpp W/System.err: org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: '172.16.50.52:5222' failed because java.net.ConnectException: failed to connect to /172.16.50.52 (port 5222) after 30000ms: connect failed: ENETUNREACH (Network is unreachable)
这些都是我的依赖
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'org.igniterealtime.smack:smack-android:4.1.6'
compile 'org.igniterealtime.smack:smack-tcp:4.1.6'
compile 'org.igniterealtime.smack:smack-im:4.1.6'
compile 'org.igniterealtime.smack:smack-extensions:4.1.6'
如果您的客户端不在服务器的网络中,则必须使用服务器的真实IP。另外,如果你的服务器在NAT后面,你必须打开TCP端口(5222) – cherif