收到“ XMPPException $ XMPPErrorException:XMPPError:service-unavailable-Cancel”使用XMPP创建群组时(4.1.3) [英] getting "XMPPException$XMPPErrorException: XMPPError: service-unavailable - cancel" while creating group using XMPP (4.1.3)

查看:290
本文介绍了收到“ XMPPException $ XMPPErrorException:XMPPError:service-unavailable-Cancel”使用XMPP创建群组时(4.1.3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用XMPP(4.1.3)创建聊天组时遇到问题。

I am facing issue while creating chat group using XMPP(4.1.3).

我的代码是

       try{

            // Get the MultiUserChatManager
            MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(ClosrrService.xmppConnection);

            Log.e("Connection  : ", ClosrrService.xmppConnection.toString());

            // Get a MultiUserChat using MultiUserChatManager
            MultiUserChat muc = manager.getMultiUserChat("dayaroom@conference."+Constants.HOST);

            // Create the room and send an empty configuration form to make this an instant room
            muc.create("testbotdaya");

            muc.sendConfigurationForm(new Form(DataForm.Type.submit));


        }catch (Exception e) {
            e.printStackTrace();
        }

在上面的代码中, muc出现异常。 create( testbotdaya); ,并且例外是

In above code I am getting exception on muc.create("testbotdaya"); and exception is

org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: service-unavailable - cancel
 W/System.err﹕ at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:232)
 W/System.err﹕ at org.jivesoftware.smackx.muc.MultiUserChat.enter(MultiUserChat.java:311)
 W/System.err﹕ at org.jivesoftware.smackx.muc.MultiUserChat.createOrJoin(MultiUserChat.java:400)
 at org.jivesoftware.smackx.muc.MultiUserChat.createOrJoin(MultiUserChat.java:376)
 W/System.err﹕ at org.jivesoftware.smackx.muc.MultiUserChat.create(MultiUserChat.java:354)
 W/System.err﹕ at com.rappier.closrr.chat.grpupchat.CreateGroupActivity.createGroup(CreateGroupActivity.java:82)
 W/System.err﹕ at com.rappier.closrr.chat.grpupchat.CreateGroupActivity.onClick(CreateGroupActivity.java:64)

请帮助我。

推荐答案

我也遇到了同样的问题,但是经过大量研究,我找到了解决方案。

I also get the same issue but after lots of research, I found the solution.

这里是我正在使用的create Group方法,请检查您的代码,请与我的代码进行比较,以便您查找错误。

Here is create Group method which I'm using, I check your code, please compare with my code so you can find your mistake.

public boolean createGroup() {
    try {
        String myJid = "MY_JID";
        String grp_name = "TestGroup";

        //creating unique group id using
        String groupId = grp_name.toLowerCase() + "_" + String.valueOf(System.currentTimeMillis() / 1000L);

        //this list for send invitations if you need.
        ArrayList<String> friendList = new ArrayList<>();
        friendList.add("friendNameJID1");
        friendList.add("friendNameJID2");
        friendList.add("friendNameJID3");


        if (TextUtils.isEmpty(grp_name) || TextUtils.isEmpty(groupId)) {
            return false;
        }

        // Create the XMPP address (JID) of the MUC.
        EntityBareJid mucJid = JidCreate.entityBareFrom(groupId + "@conference.localhost");//groupId@conference.domain name
        // Create the nickname.
        Resourcepart nickname = Resourcepart.from(myJid);
        // Get the MultiUserChatManager
        MultiUserChatManager mucChatManager = MultiUserChatManager.getInstanceFor(MyApplication.connection);
        // Get a MultiUserChat using MultiUserChatManager
        MultiUserChat mucChat = mucChatManager.getMultiUserChat(mucJid);


        try {

            // Create the room
            mucChat.create(nickname);


            Form form = mucChat.getConfigurationForm();
            Form submitForm = form.createAnswerForm();

            for (FormField formField : submitForm.getFields()) {

                if (!FormField.Type.hidden.equals(formField.getType())
                        && formField.getVariable() != null) {
                    submitForm.setDefaultAnswer(formField.getVariable());
                }
            }


            submitForm.setAnswer("muc#roomconfig_publicroom", true);
            submitForm.setAnswer("muc#roomconfig_persistentroom", true);
            submitForm.setAnswer("muc#roomconfig_roomname", grp_name);


            mucChat.sendConfigurationForm(submitForm);

            mucChat.join(nickname);

            for (String names : friendList) {

                Message message = new Message();
                // message.setType(Type.normal);  //optional
                message.setSubject(Constants.GROUP_CHAT_MSG_MODE);
                message.setBody(Constants.GROUP_GREETINGS);

                EntityBareJid eJId = JidCreate.entityBareFrom(names + "@" + Constants.XMPP_DOMAIN);
                mucChat.invite(message, eJId, groupId);

            }

            return true;

        } catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {

            Log.d(TAG, "Group is already there " + Arrays.toString(e.getStackTrace()));
            return false;
        } catch (MultiUserChatException.MucAlreadyJoinedException e) {

            Log.d(TAG, "Group Error : " + e.getMessage());
            return false;
        }

    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | XmppStringprepException | MultiUserChatException.NotAMucServiceException e) {
        Log.d(TAG, "Group Error : " + e.getMessage());
        return false;
    } catch (SmackException.NotConnectedException e) {
        Log.d(TAG, "Group Error : " + e.getMessage());
        return false;
    }
}

这篇关于收到“ XMPPException $ XMPPErrorException:XMPPError:service-unavailable-Cancel”使用XMPP创建群组时(4.1.3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆