Openfire 不响应 Smack login()
Posted
技术标签:
【中文标题】Openfire 不响应 Smack login()【英文标题】:Openfire does not respond to Smack login() 【发布时间】:2016-04-13 04:00:04 【问题描述】:我正在使用 Smack API 尝试连接并登录到我的笔记本电脑 (localhost) 上设置的 Openfire XMPP 服务器。
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() 方法成功,但 login() 方法失败并出现 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 服务器设置?
另外,我尝试使用Spark IM client登录,它可以毫无问题地登录本地服务器。
问候。
下面添加了更多信息。
我刚刚尝试了从Spark IM github repo 获得的旧版本(3.4.1)smack,代码如下:
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。
【问题讨论】:
我m using last version of Smack and login like you, and its working fine. I have no access to my code now, in 3 hours i
会尽力帮助你
【参考方案1】:
让我们一步一步开始
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);
【讨论】:
以上是关于Openfire 不响应 Smack login()的主要内容,如果未能解决你的问题,请参考以下文章
使用 Smack 和 Openfire 发送/接收消息时遇到问题
运行 localhost openfire 和 smack 客户端库 android