0

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?

Jennifer
  • 351
  • 6
  • 18
  • 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 Jul 06 '16 at 07:47
  • @Flow i am sorry for not clearing my question firstly. i am working forwardly for solution – Jennifer Jul 08 '16 at 05:42

1 Answers1

2

Simply use MultiUserChat.sendMessage().

Flow
  • 23,572
  • 15
  • 99
  • 156
  • Yes i have send the message and listener is also responding to that. My question is how will i show that message to another users? – Jennifer Jul 06 '16 at 07:33
  • I'm sorry, but I don't understand the question. – Flow Jul 06 '16 at 07:34
  • 1
    @Jennifer you have to trust more who reply you ;) Simply any client will be automatically notificated by his own listener. To be notified a client must join the room and stay in the room abd add a listener, so it's all automatized – MrPk Jul 06 '16 at 08:10
  • @MrPk Yes i do trust who reply me. It was just that i was away for sometime. So I could not reply. I will try to implement the answer. – Jennifer Jul 08 '16 at 05:38