-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