MultiUserchat.join() method never returns

Hello Smack devs,

I am trying to join all the MultiUserChat as soon as my client got authenticated. I managed to store a list of joined MUC on client side but i am facing following issue while doing that.

When my client got authenticated and then when i execute the MultiUserChat.join() this method never returns and i can join only the one room at the moment and i can see that user has joined a MUC on the server side as well as i can send/receive a message to that MUC.

Is there any way that i can join multiple MUC at the same time and can set up a listners on each MUC so i can receive a messages from each and every MUC which i am part of.

I am attaching the code snippet of my Main method which is as per following


public static void main(final String[] args) {

		Scanner sc = new Scanner(System.in);

		System.out.println("enter username ");
		final String username = sc.nextLine();

		System.out.println("enter password ");
		final String password = sc.nextLine();

		try {

			// This method will give you TCP connection object from the smack.
			final XMPPTCPConnection connection = GetXmppConnection.getConnection(username, password);
			System.out.println(
					"Connected :-  " + connection.isConnected() + " Authenicated " + connection.isAuthenticated());

			System.out.println("Enter Room id");
			final MultiUserChatManager mucManager = MultiUserChatManager.getInstanceFor(connection);

			Thread thread = new Thread(new Runnable() {

				@Override
				public void run() {

					try {

						MultiUserChat muc = mucManager
								.getMultiUserChat(JidCreate.entityBareFrom("abcd@conference.domain"));

						Resourcepart nickName = Resourcepart.from(username);
						MucEnterConfiguration mucEnterConfiguration = muc.getEnterConfigurationBuilder(nickName)
								.requestNoHistory().build();

						if (!muc.isJoined()) {
							muc.join(mucEnterConfiguration);
						}

						// This code will never execute.
						System.out.println("Muc Joined sucessfully !!! ");

						Set joinedRooms = mucManager.getJoinedRooms();

						for (EntityBareJid entityBareJid : joinedRooms) {
							System.out.println(String.format("Room name %s", entityBareJid.asBareJid()));
						}

						System.out.println(String.format("%s Room joined sucessfully", "abcd"));

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

				}
			});
			thread.start();

			System.out.println("Press something to send a message");
			String line = sc.nextLine();

			while (!line.equals("stop")) {

				System.out.println("To : - ");
				String to = sc.nextLine();

				System.out.println("Enter Message to send :- ");
				String body = sc.nextLine();

				String stanzaId = String.valueOf(new Date().getTime());

				Message message = new Message();
				message.setTo(JidCreate.from(to));
				message.setBody(body);
				message.setStanzaId(String.valueOf(stanzaId));
				message.setType(Type.groupchat);
				connection.sendStanza(message);

				System.out.println(String.format("Message %s ", message.toXML(null)));

				System.out.println("Press stop to stop sending message or something else to continue again");
				line = sc.nextLine();

			}

			sc.nextLine();

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

		sc.close();
	}

I am using following libs to make this happen

Smack - 4.3.4
openfire - 4.4.2
Java JDK - 1.8

Please suggest anything or let me know if i am doing anything wrong.

Thanks

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.