组件使用: ejabberd- 18.06 和 SMACK-4.2.4
我已经在PC中安装了 Spark ejabberd客户端,并且可以在其中创建聊天室。但是当我朗读下面的代码时,它会得到以下异常。我也在连接到同一局域网的Android模拟器和手机上进行了尝试。
SMACK错误:
W/System.err: org.jivesoftware.smackx.muc.MultiUserChatException$NotAMucServiceException: Can not join 'mamun@localhost', because 'localhost' does not provide a MUC (XEP-45) service.
at org.jivesoftware.smackx.muc.MultiUserChat.enter(MultiUserChat.java:314)
W/System.err: at org.jivesoftware.smackx.muc.MultiUserChat.createOrJoin(MultiUserChat.java:498)
at org.jivesoftware.smackx.muc.MultiUserChat.createOrJoin(MultiUserChat.java:444)
at org.jivesoftware.smackx.muc.MultiUserChat.create(MultiUserChat.java:419)
at time.friends.myapplication.GroupChat$1.onClick(GroupChat.java:58)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
SMACK来源:
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(
SessionHolder.abstractXMPPConnection);
MultiUserChat muc = manager.getMultiUserChat(
getEntityBareJid(SessionHolder.abstractXMPPConnection.getUser()+""));
Log.e("Group","Group created successfully");
try {
muc.create(getResourcepart(grp.getText()+"")).makeInstant();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucAlreadyJoinedException e) {
e.printStackTrace();
} catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
}
此处 manager.isServiceEnabled 返回true。
ejabberd配置:
hosts:
- "localhost"
....
access_rules:
## This rule allows access only for local users:
##local:
## - allow: local
## Only non-blocked users can use c2s connections:
c2s:
- deny: blocked
- allow
## Only admins can send announcement messages:
announce:
- allow: admin
## Only admins can use the configuration interface:
configure:
- allow: admin
## Only accounts of the local ejabberd server can create rooms:
muc_create:
- allow: all
....
modules:
....
mod_muc:
## host: "conference.localhost"
access: all
access_admin: muc_admin
access_create: all
access_persistent: muc_create
## default_room_options:
## allow_subscription: true
## mod_muc_admin: {}
## mod_muc_log: {}
## mod_multicast: {}
我还尝试了 host:“ conference.localhost” 和 host:“ conference。@ HOST @” 对此未加注释。
ejabberd日志:
#iq{id = <<"Z4XNM-14">>,type = get,lang = <<"en">>,
from = #jid{user = <<"mamun">>,server = <<"localhost">>,
resource = <<"6215854561312688131227">>,luser = <<"mamun">>,
lserver = <<"localhost">>,
lresource = <<"6215854561312688131227">>},
to = #jid{user = <<>>,server = <<"conference.localhost">>,resource = <<>>,
luser = <<>>,lserver = <<"conference.localhost">>,
lresource = <<>>},
sub_els = [#xmlel{name = <<"query">>,
attrs = [{<<"xmlns">>,
<<"http://jabber.org/protocol/disco#info">>}],
children = []}],
meta = #{ip => {192,168,1,3}}}
2018-08-18 23:04:05.198 [debug] <0.550.0>@mod_stream_mgmt:check_h_attribute:480 mamun@localhost/6215854561312688131227 acknowledged 3 of 3 stanzas
2018-08-18 23:04:05.201 [debug] <0.476.0>@ejabberd_router:do_route:352 route:
#iq{id = <<"Z4XNM-14">>,type = result,lang = <<"en">>,
from =
#jid{
user = <<>>,server = <<"conference.localhost">>,resource = <<>>,
luser = <<>>,lserver = <<"conference.localhost">>,
lresource = <<>>},
to =
#jid{
user = <<"mamun">>,server = <<"localhost">>,
resource = <<"6215854561312688131227">>,luser = <<"mamun">>,
lserver = <<"localhost">>,
lresource = <<"6215854561312688131227">>},
sub_els =
[#disco_info{
node = <<>>,
identities =
[#identity{
category = <<"conference">>,type = <<"text">>,
lang = <<>>,name = <<"Chatrooms">>}],
features =
[<<"http://jabber.org/protocol/disco#info">>,
<<"http://jabber.org/protocol/disco#items">>,
<<"http://jabber.org/protocol/muc">>,<<"vcard-temp">>,
<<"urn:xmpp:mucsub:0">>,
<<"http://jabber.org/protocol/muc#unique">>,
<<"jabber:iq:register">>,
<<"http://jabber.org/protocol/rsm">>,<<"urn:xmpp:mam:tmp">>,
<<"urn:xmpp:mam:0">>,<<"urn:xmpp:mam:1">>,
<<"urn:xmpp:mam:2">>],
xdata =
[#xdata{
type = result,instructions = [],title = undefined,
reported = undefined,items = [],
fields =
[#xdata_field{
label = <<>>,type = hidden,
var = <<"FORM_TYPE">>,required = false,
desc = <<>>,
values =
[<<"http://jabber.org/network/serverinfo">>],
options = [],sub_els = []}]}]}],
meta = #{ip => {192,168,1,3}}}
2018-08-18 23:04:05.204 [debug] <0.476.0>@ejabberd_local:do_route:141 local route:
#iq{id = <<"Z4XNM-14">>,type = result,lang = <<"en">>,
from =
#jid{
user = <<>>,server = <<"conference.localhost">>,resource = <<>>,
luser = <<>>,lserver = <<"conference.localhost">>,
lresource = <<>>},
to =
#jid{
user = <<"mamun">>,server = <<"localhost">>,
resource = <<"6215854561312688131227">>,luser = <<"mamun">>,
lserver = <<"localhost">>,
lresource = <<"6215854561312688131227">>},
sub_els =
[#disco_info{
node = <<>>,
identities =
[#identity{
category = <<"conference">>,type = <<"text">>,
lang = <<>>,name = <<"Chatrooms">>}],
features =
[<<"http://jabber.org/protocol/disco#info">>,
<<"http://jabber.org/protocol/disco#items">>,
<<"http://jabber.org/protocol/muc">>,<<"vcard-temp">>,
<<"urn:xmpp:mucsub:0">>,
<<"http://jabber.org/protocol/muc#unique">>,
<<"jabber:iq:register">>,
<<"http://jabber.org/protocol/rsm">>,<<"urn:xmpp:mam:tmp">>,
<<"urn:xmpp:mam:0">>,<<"urn:xmpp:mam:1">>,
<<"urn:xmpp:mam:2">>],
xdata =
[#xdata{
type = result,instructions = [],title = undefined,
reported = undefined,items = [],
fields =
[#xdata_field{
label = <<>>,type = hidden,
var = <<"FORM_TYPE">>,required = false,
desc = <<>>,
values =
[<<"http://jabber.org/network/serverinfo">>],
options = [],sub_els = []}]}]}],
meta = #{ip => {192,168,1,3}}}
2018-08-18 23:04:05.207 [debug] <0.476.0>@ejabberd_sm:do_route:651 processing packet to full JID:
#iq{id = <<"Z4XNM-14">>,type = result,lang = <<"en">>,
from =
#jid{
user = <<>>,server = <<"conference.localhost">>,resource = <<>>,
luser = <<>>,lserver = <<"conference.localhost">>,
lresource = <<>>},
to =
#jid{
user = <<"mamun">>,server = <<"localhost">>,
resource = <<"6215854561312688131227">>,luser = <<"mamun">>,
lserver = <<"localhost">>,
lresource = <<"6215854561312688131227">>},
sub_els =
[#disco_info{
node = <<>>,
identities =
[#identity{
category = <<"conference">>,type = <<"text">>,
lang = <<>>,name = <<"Chatrooms">>}],
features =
[<<"http://jabber.org/protocol/disco#info">>,
<<"http://jabber.org/protocol/disco#items">>,
<<"http://jabber.org/protocol/muc">>,<<"vcard-temp">>,
<<"urn:xmpp:mucsub:0">>,
<<"http://jabber.org/protocol/muc#unique">>,
<<"jabber:iq:register">>,
<<"http://jabber.org/protocol/rsm">>,<<"urn:xmpp:mam:tmp">>,
<<"urn:xmpp:mam:0">>,<<"urn:xmpp:mam:1">>,
<<"urn:xmpp:mam:2">>],
xdata =
[#xdata{
type = result,instructions = [],title = undefined,
reported = undefined,items = [],
fields =
[#xdata_field{
label = <<>>,type = hidden,
var = <<"FORM_TYPE">>,required = false,
desc = <<>>,
values =
[<<"http://jabber.org/network/serverinfo">>],
options = [],sub_els = []}]}]}],
meta = #{ip => {192,168,1,3}}}
2018-08-18 23:04:05.210 [debug] <0.476.0>@ejabberd_sm:do_route:675 sending to process <0.550.0>:
#iq{id = <<"Z4XNM-14">>,type = result,lang = <<"en">>,
from =
#jid{
user = <<>>,server = <<"conference.localhost">>,resource = <<>>,
luser = <<>>,lserver = <<"conference.localhost">>,
lresource = <<>>},
to =
#jid{
user = <<"mamun">>,server = <<"localhost">>,
resource = <<"6215854561312688131227">>,luser = <<"mamun">>,
lserver = <<"localhost">>,
lresource = <<"6215854561312688131227">>},
sub_els =
[#disco_info{
node = <<>>,
identities =
[#identity{
category = <<"conference">>,type = <<"text">>,
lang = <<>>,name = <<"Chatrooms">>}],
features =
[<<"http://jabber.org/protocol/disco#info">>,
<<"http://jabber.org/protocol/disco#items">>,
<<"http://jabber.org/protocol/muc">>,<<"vcard-temp">>,
<<"urn:xmpp:mucsub:0">>,
<<"http://jabber.org/protocol/muc#unique">>,
<<"jabber:iq:register">>,
<<"http://jabber.org/protocol/rsm">>,<<"urn:xmpp:mam:tmp">>,
<<"urn:xmpp:mam:0">>,<<"urn:xmpp:mam:1">>,
<<"urn:xmpp:mam:2">>],
xdata =
[#xdata{
type = result,instructions = [],title = undefined,
reported = undefined,items = [],
fields =
[#xdata_field{
label = <<>>,type = hidden,
var = <<"FORM_TYPE">>,required = false,
desc = <<>>,
values =
[<<"http://jabber.org/network/serverinfo">>],
options = [],sub_els = []}]}]}],
meta = #{ip => {192,168,1,3}}}
答案 0 :(得分:1)
问题出在这里-
**MultiUserChat muc = manager.getMultiUserChat(
getEntityBareJid(SessionHolder.abstractXMPPConnection.getUser()+""));**
参数名称格式应
Group_Name@conference.HOST_NAME
i.e-myroom@conference.localhost
这对我有用。 :)