Search code examples
xmppsmackmultiuserchat

How to send message to all participants of multi user chat room using smack


I am creating multi user chat room for group chat where multi user can have chat. I am using smack for this within jsp . I have added message listener for multi user chat room after joining the room.

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

        // Create a MultiUserChat using an CustomXMPPConnection for a room
        MultiUserChat multiUserChat = manager.getMultiUserChat(chatRoomName + "@conference." + xmppConnection.getServiceName());

        multiUserChat.addMessageListener(new MessageListener()
        {
            @Override
            public void processMessage(Message message) {
                System.out.println("Message listener Received message in send message: "
                        + (message != null ? message.getBody() : "NULL") + "  , Message sender :" + message.getFrom());
            }
        });

Code for sending message :

Message message = new Message(chatRoomName, Message.Type.groupchat);
message.setBody(msg);
message.setType(Message.Type.groupchat);
message.setTo(chatRoomName);
multiUserChat.sendMessage(message);

My question is after receiving message in Message Listener how will i show message to other users?


Solution

  • Simply use MultiUserChat.sendMessage().