服务器:ejabberd2 XMPP:smack 3.3.1
目标是设计聊天引擎。用户通过输入用户名应该能够确定输入的用户名是否已在服务器上注册。
The Smack Javadocs can be found here
我想查找服务器上是否已存在用户名。我使用的代码及其得到的错误如下所示。
UserSearchManager search = new UserSearchManager(connection);
Form searchForm = search.getSearchForm("search."+connection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", name);
ReportedData data = search.getSearchResults(answerForm,"search."+connection.getServiceName());
以上代码输出以下错误:
service-unavailable(503)
at org.jivesoftware.smackx.search.UserSearch.getSearchForm(UserSearch.java:84)
at org.jivesoftware.smackx.search.UserSearchManager.getSearchForm(UserSearchManager.java:73)
at com.phanism.www.XmppConnect.searchUser(XmppConnect.java:74)
at com.phanism.www.XmppConnect.main(XmppConnect.java:97)
答案 0 :(得分:0)
您尚未设置要搜索的用户名。
erSearchManager search = new UserSearchManager(connection);
Form searchForm = search.getSearchForm("search."+connection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", name);//Here username must be added name replace by "amith"
然后它会起作用.. :)