我正在使用Smack,试图连接并登录到Openfire XMPP服务器,它是在我的笔记本电脑(localhost)上安装的。
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
.setServiceName("win10-xps15")
.setHost("192.168.1.100")
.setPort(5222)
.setCompressionEnabled(false)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.build();
XMPPTCPConnection connection = new XMPPTCPConnection(conf);
connection.connect();
connection.login("admin", "password");connect()方法成功,但NoResponse (超时值)异常导致登录()方法失败。
Exception in thread "main" org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'.
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:106)
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:85)
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:250)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnection.java:374)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:456)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:431)
at MyConnector.main(MyConnector.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Apr 13, 2016 11:45:42 AM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection closed with error
java.lang.NullPointerException
at org.jivesoftware.smack.util.stringencoder.Base64.decode(Base64.java:86)
at org.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java:233)
at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:328)
at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:313)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1051)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:948)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:963)
at java.lang.Thread.run(Thread.java:745) 我在我的Windows笔记本上运行Openfire 3.9.3,本地IP是192.168.1.100。smack库的版本为4.1.6。
因为失败的是login()方法,所以我想知道是否有任何与登录/用户相关的Openfire服务器设置是我应该知道的?
此外,我尝试用火花IM客户端登录,它可以毫无问题地登录本地服务器。
致以问候。
更多的信息添加到下面。
我刚刚尝试了从火花IM github回购获得的一个旧版本的smack (3.4.1),代码如下:
ConnectionConfiguration conf =
new ConnectionConfiguration("192.168.1.100", 5222);
XMPPConnection connection = new XMPPConnection(conf);
connection.connect();
connection.login("admin", "password");现在代码工作正常。connect()和login()都正常。
但是我真的想知道为什么最近版本的smack不能像我预期的那样工作。因为我考虑在Android上使用smack,而旧版本不支持Android。
发布于 2018-01-23 07:41:11
让我们从一步一步开始
1)添加依赖项
compile 'org.igniterealtime.smack:smack-tcp:4.1.0'
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.0'
compile 'org.igniterealtime.smack:smack-im:4.1.0'2)连接或登录到服务器的异步任务
//connect or login to server
private class MyOpenfireLoginTask extends AsyncTask<String, String, String> {
private Context mContext;
String username, password;
ProgressDialog dialog;
public MyOpenfireLoginTask(Context context) {
mContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(mContext);
dialog.setMessage("Loading...");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
@Override
protected String doInBackground(String... params) {
username = params[0];
password = params[1];
Log.e("Login using ", username + " , " + password);
Config.config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(username, password)
.setHost("your host ex- wec.com")
.setResource("Android")
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setServiceName("domain name(@) ex- secureserver.net")
.setPort("5222")
.setDebuggerEnabled(true)
.build();
Config.conn1 = new XMPPTCPConnection(Config.config);
Config.conn1.setPacketReplyTimeout(5000);
try {
Config.conn1.connect();
if (Config.conn1.isConnected()) {
Log.w("app", "conn done");
}
Config.conn1.login();
if (Config.conn1.isAuthenticated()) {
Log.w("app", "Auth done");
} else {
Log.e("User Not Authenticated", "Needs to Update Password");
}
} catch (Exception e) {
Log.w("app", e.toString());
}
return "";
}
@Override
protected void onPostExecute(String result) {
dialog.dismiss();
if (Config.conn1.isAuthenticated()) {
//success
} else {
Log.e(TAG, "username password wrong");
}
}
}3)执行上述类
if (username.length() > 0 && password.length() > 0) {
MyOpenfireLoginTask task = new MyOpenfireLoginTask(activity);
task.execute(username, password);
}https://stackoverflow.com/questions/36588324
复制相似问题