0
votes

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?

1
Your question made a 180° turn. First it was "how can I send a message to all participants of a multi user chat?" (this is was the title still says), now it's "how can I display a message once I received it in a message listener?". That obviously depends on whatever you use to interact with the user, in your case likely JSP. So maybe some kind of browser notification and/or however you visualize the chat?Flow
@Flow i am sorry for not clearing my question firstly. i am working forwardly for solutionJennifer

1 Answers

2
votes

Simply use MultiUserChat.sendMessage().