Android 获得$XMPPError异常:XMPPError:禁止-auth;创建多用户聊天时出错

Android 获得$XMPPError异常:XMPPError:禁止-auth;创建多用户聊天时出错,android,exception,smack,Android,Exception,Smack,我已经使用Smack Api(4.1.4)成功地为XMPP创建了登录连接。现在我正在尝试使用创建多用户聊天 try { String myMUCName = "TestGroup"; String myMUCService = "conference.(my local ip)"; String myMUCfullName = myMUCName + "@" + myMUCService; String userName =

我已经使用Smack Api(4.1.4)成功地为XMPP创建了登录连接。现在我正在尝试使用创建多用户聊天

    try {
        String myMUCName = "TestGroup";
        String myMUCService = "conference.(my local ip)";
        String myMUCfullName = myMUCName + "@" + myMUCService;
        String userName =  "Test5";

        MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
        MultiUserChat muc = manager.getMultiUserChat(myMUCfullName);
        muc.create(userName);

        Log.d(LOCAL_TAG, "createGroupChat  -- Group CEATED Successfully ");
        Form form = muc.getConfigurationForm();
        Form submitForm = form.createAnswerForm();

        List<FormField> fields = form.getFields();
        Log.d(LOCAL_TAG, "createGroupChat  -- fields.size(): "+fields.size());
        for (int i = 0; i < fields.size(); i++) {
            FormField field = (FormField) fields.get(i);
            if (!FormField.Type.hidden.equals(field.getType()) && field.getVariable() != null) {
                submitForm.setDefaultAnswer(field.getVariable());
            }
        }

        List owners = new ArrayList();
        owners.add(userName); //Own user
        owners.add("Test7"); //Another user

        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        submitForm.setAnswer("muc#roomconfig_publicroom", true);
        submitForm.setAnswer("muc#roomconfig_persistentroom", true);
        muc.sendConfigurationForm(new Form(DataForm.Type.submit));
        //muc.sendConfigurationForm(submitForm);
    Log.d(LOCAL_TAG, "createGroupChat  -- Sent Configuration");
        muc.join(TestGroup);
        Log.d(LOCAL_TAG, "createGroupChat  -- Group Joined Successfully -- owners.size(): "+owners.size());
希望如此,此异常发生在代码中

   muc.sendConfigurationForm(submitForm);
因为这个原因,我们在这篇文章中对它进行了评论。因为在那代码之后我没有得到日志。为了解决这个问题,我将代码改为

   muc.sendConfigurationForm(new Form(DataForm.Type.submit));
它修复了这个异常并为我创建了一个组,因为我可以看到打印的日志,也可以在明火中看到我的组。但我确实知道,通过这样做,我为该组选择的用户是如何添加的,因为在任何地方,所有者列表(或提交表单)都不包括在其中。我不知道这里面发生了什么,我也不确定我做得对不对。请告诉我如何进行。提前感谢。

请尝试以下代码:

Form form = muc.getConfigurationForm().createAnswerForm();


        // Create a new form to submit based on the original form
        form.setAnswer("muc#roomconfig_passwordprotectedroom", false);
        form.setAnswer("muc#roomconfig_roomname",myMUCName);
        form.setAnswer("muc#roomconfig_persistentroom", true);
        form.setAnswer("muc#roomconfig_changesubject", true);
        form.setAnswer("muc#roomconfig_publicroom",true);
        form.setAnswer("muc#roomconfig_allowinvites",true);
        form.setAnswer("muc#roomconfig_membersonly",false);
        form.setAnswer("muc#roomconfig_moderatedroom",false);

        // Sets the new owner of the room
        List<String> owners = new ArrayList<String>();

        //Be carefull: if members does not exists, it brokes!

        owners.add(userName +"@"+"(my local ip or server name placeholder)");
        form.setAnswer("muc#roomconfig_roomowners", owners);

        // Send the completed form
        muc.sendConfigurationForm(form);
        System.out.println("MUC is now registered");

        muc.join(userName );
然后,如果你想看到他们“永远”

这样你就可以看到会员资格了

muc.getMembers();
请注意: 附属:在MUC中具有定义角色(Onwer、Admin、Member、Outcast)的用户 用户:MUC中的在线用户

并非所有占用者都可以担任角色,也并非所有附属机构都自动成为占用者

更重要的是,你不能确定是否有会员加入了groupchat

Flux的意思是:

用户1创建Muc (可选)User1向他想要的任何用户发出Muc邀请(例如:User2、User4) (可选)User1将Muc附属机构分配给其所需的任何现有用户(例如:User3、User4)

在线时,User2和User4将收到接受/拒绝邀请 User3和User4不会收到任何信息,但它们将在MUC中扮演角色


用户2、用户3、用户4需要注册IQProviders以获得IQ节,然后每个MUC的列表器接收邀请,另一个MUC接收消息(和或其他事件)。

对于SMACK 4.3.4及以上版本

        multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);

        multiUserChat = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(roomJID));

        multiUserChat.create(Resourcepart.from(nickname));

        Form form = multiUserChat.getConfigurationForm();
        Form submitForm = form.createAnswerForm(); submitForm.getField("muc#roomconfig_publicroom").addValue("1");
        submitForm.getField("muc#roomconfig_enablelogging").addValue("1");
        submitForm.getField("x-muc#roomconfig_reservednick").addValue("0");
        submitForm.getField("x-muc#roomconfig_canchangenick").addValue("0");
        submitForm.getField("x-muc#roomconfig_registration").addValue("0");
        submitForm.getField("muc#roomconfig_passwordprotectedroom").addValue("0");
        submitForm.getField("muc#roomconfig_roomname").addValue(roomName);
        submitForm.getField("muc#roomconfig_whois").addValue("participants");
        submitForm.getField("muc#roomconfig_membersonly").addValue("1");
        submitForm.getField("muc#roomconfig_persistentroom").addValue("1");
        multiUserChat.sendConfigurationForm(submitForm);

这就是如何从发送文件室配置并创建文件室(MUC)。

Hi。。非常感谢您的回复。它修正了这个例外。但当我试图用那个代码邀请用户时,我并没有收到其他用户的任何邀请通知,即使第二个用户在线。我以“muc.invite(“test7@(域名)”,“在这个极好的房间见我”);muc.grantMembership(“test7@(域名)”);muc.getMembers();”的身份邀请了第二个用户。如何检查我是否发送了邀请,而其他用户是否收到了该邀请。在muc代码中,不需要添加domain.name,但是请确保注册InvitationListener(MultiUserChatManager.addInvitationListener(new InvitationListener)。我建议也在javadoc上签出这些类;)嗨@Sangeetha我也遇到了同样的问题,你能描述一下你是如何解决这个错误的吗?嗨@Sangeetha我也遇到了同样的问题,你能描述一下你是如何解决这个错误的吗?
muc.invite(user, "Invite");
muc.grantMembership(user);
muc.getMembers();
        multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);

        multiUserChat = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(roomJID));

        multiUserChat.create(Resourcepart.from(nickname));

        Form form = multiUserChat.getConfigurationForm();
        Form submitForm = form.createAnswerForm(); submitForm.getField("muc#roomconfig_publicroom").addValue("1");
        submitForm.getField("muc#roomconfig_enablelogging").addValue("1");
        submitForm.getField("x-muc#roomconfig_reservednick").addValue("0");
        submitForm.getField("x-muc#roomconfig_canchangenick").addValue("0");
        submitForm.getField("x-muc#roomconfig_registration").addValue("0");
        submitForm.getField("muc#roomconfig_passwordprotectedroom").addValue("0");
        submitForm.getField("muc#roomconfig_roomname").addValue(roomName);
        submitForm.getField("muc#roomconfig_whois").addValue("participants");
        submitForm.getField("muc#roomconfig_membersonly").addValue("1");
        submitForm.getField("muc#roomconfig_persistentroom").addValue("1");
        multiUserChat.sendConfigurationForm(submitForm);