gpt4 book ai didi

xmpp - 如何使用 Smack 在 XMPP 服务器中按名称搜索注册用户?

转载 作者:行者123 更新时间:2023-12-04 10:17:59 24 4
gpt4 key购买 nike

我正在使用 asmack 库在 Android 中开发聊天应用程序。我正在使用 EJABBERD XMPP 服务器。我已经完成了一些功能,包括登录、注册和名册条目等,

现在我想从 XMPP 服务器搜索注册用户以发送好友请求。我用谷歌搜索并尝试了一些代码,但仍然没有成功。

我正在使用以下代码从 XMPP 服务器搜索用户。

UserSearchManager userSearchManager = new UserSearchManager(connection);
Form searchForm = userSearchManager.getSearchForm("search." + connection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Name", true);
answerForm.setAnswer("search", "test"); // here i'm passsing the Text value to search

ReportedData resultData;
resultData = userSearchManager.getSearchResults(answerForm, "search."+ connection.getServiceName());

Iterator<Row> it = resultData.getRows();
Row row = null;
while (it.hasNext()) {
String value = it.next().toString();
Log.i("Iteartor values......", " " + value);
System.out.println("Jabber_id :" + row.getValues("jid").next().toString());
System.out.println("Name :" + row.getValues("Name").next().toString());
row = it.next();
}

当我执行上述代码时。我在 LogCat 中收到以下错误。
service-unavailable(503)

at org.jivesoftware.smackx.search.UserSearch.getSearchForm(UserSearch.java:84)

at org.jivesoftware.smackx.search.UserSearchManager.getSearchForm(UserSearchManager.java:73)

需要进行哪些更改才能获得搜索结果?

ejabberd.cfg
%%%   =======
%%% MODULES

%%
%% Modules enabled in all ejabberd virtual hosts.
%%
{modules,
[
{mod_adhoc, []},
{mod_announce, [{access, announce}]}, % requires mod_adhoc
{mod_caps, []},
{mod_configure,[]}, % requires mod_adhoc
{mod_admin_extra, []},
{mod_disco, []},
%%{mod_echo, [{host, "echo.localhost"}]},
{mod_irc, []},
%% NOTE that mod_http_fileserver must also be enabled in the
%% "request_handlers" clause of the "ejabberd_http" listener
%% configuration (see the "LISTENING PORTS" section above).
%%{mod_http_fileserver, [
%% {docroot, "/var/www"},
%% {accesslog, "/var/log/ejabberd/access.log"}
%% ]},
{mod_last, []},
{mod_muc, [
%%{host, "conference.@HOST@"},
{access, muc},
{access_create, muc},
{access_persistent, muc},
{access_admin, muc_admin},
{max_users, 500}
]},
%%{mod_muc_log,[]},
{mod_offline, [{access_max_user_messages, max_user_offline_messages}]},
{mod_privacy, []},
{mod_private, []},
{mod_proxy65, [
{access, local},
{shaper, c2s_shaper}
]},
{mod_pubsub, [ % requires mod_caps
{access_createnode, pubsub_createnode},
{pep_sendlast_offline, false},
{last_item_cache, false},
%%{plugins, ["default", "pep"]}
{plugins, ["flat", "hometree", "pep"]} % pep requires mod_caps
]},
{mod_register, [
%%
%% After successful registration, the user receives
%% a message with this subject and body.
%%
{welcome_message, {"Welcome!",
"Welcome to a Jabber service powered by Debian. "
"For information about Jabber visit "
"http://www.jabber.org"}},
%% Replace it with 'none' if you don't want to send such message:
%%{welcome_message, none},

%%
%% When a user registers, send a notification to
%% these Jabber accounts.
%%
%%{registration_watchers, ["admin1@example.org"]},

{access, register}
]},
{mod_roster, []},
%%{mod_service_log,[]},
%%{mod_shared_roster,[]},
{mod_stats, []},
{mod_time, []},
{mod_vcard, []},
{mod_version, []}
]}.

最佳答案

由于ejabberd 的默认配置是保持搜索服务在vjud.example.com ,不是 search.example.com ,你需要改变这一行:

Form searchForm = userSearchManager.getSearchForm("search." + connection.getServiceName());

对此:
Form searchForm = userSearchManager.getSearchForm("vjud." + connection.getServiceName());

关于xmpp - 如何使用 Smack 在 XMPP 服务器中按名称搜索注册用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24960304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com