powered by Jive Software

How to create a MultiUserChat room which has a password

how to create a MultiUserChat room which has a password to join the room



This is untested code, but you will need to do something that is similar to the following:

// Create a MultiUserChat using an XMPPConnection for a room
      MultiUserChat muc = new MultiUserChat(conn1, "myroom@conference.jabber.org");       // Create the room
      muc.create("testbot");       // Get the the room's configuration form
      Form form = muc.getConfigurationForm();
      // Create a new form to submit based on the original form
      Form submitForm = form.createAnswerForm();
      // Add default answers to the form to submit
      for (Iterator fields = form.getFields(); fields.hasNext();) {
          FormField field = (FormField) fields.next();
          if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
              // Sets the default value as the answer
      }       // Set that the room requires a password
      submitForm.setAnswer("muc#roomconfig_passwordprotectedroom", true);
      // Set the password for the room
      submitForm.setAnswer("muc#roomconfig_roomsecret", "password");       // Send the completed form (with default values) to the server to configure the room

The basic code for this example came from here: MUC - Create a new Room

The form fields for setting a password came from here: MUC - Room Config

Hope that helps,


thanks your replay, chrisw1229.I have resolved this problem using your code.

you are very good.

my english is poor,I can’t say lots of beautiful sentences,

thank you.

Sorry, wrong thread.

How to get the new messages sent to multiuserchat…