我对android有点新意我正在尝试构建一个聊天android应用程序 使用openfire作为服务器并使用4.1.6 libs 现在我正在尝试建立一个基本的连接我正在遵循smack文档
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'
答案 0 :(得分:1)
检查您的手机或模拟器是否具有互联网连接
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
答案 1 :(得分:0)
嗨,如果将来帮助任何人我已经将ConnectionConfiguration.SecurityMode设置为禁用,并且工作正常
var map1 = Immutable.Map({a:1, b:2, c:3, d:4});
var map2 = Immutable.Map({c:10, a:20, t:30});
var obj = {d:100, o:200, g:300};
var map3 = map1.merge(map2, obj);
// Map { a: 20, b: 2, c: 10, d: 100, t: 30, o: 200, g: 300 }