0
votes

I am creating a chat application ,one to one chatting is working properly ,but when comes to multi user chat i am not able to listen their messages I am using smack for implementing the XMPP protocol Here is the code

Server configuration part is

    public void serverCongig() throws XMPPException {
     
    LOGGER.info(String.format("Initializing connection to server %1$s port 
       %2$d", server, port));
    SmackConfiguration.setPacketReplyTimeout(packetReplyTimeout);
    config = new ConnectionConfiguration(server, 
        port,PropertyReader.getPropertiesValue("server_domain"));
 //        config.setSASLAuthenticationEnabled(false);
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
     
    connection = new XMPPConnection(config);
    try
    {
       connection.connect();
        LOGGER.info("Connected: " + connection.isConnected()+" Service 
         name"+connection.getServiceName());
        chatManager = connection.getChatManager();
        messageListener = new MyMessageListener();
    }
    catch(Exception e)
    {
                    callThread();
     
        e.printStackTrace();
    }
      finally
    {
        callThread();
    }
   
     
}

Message listening part is class MyMessageListener implements MessageListener {

    @Override
    public void processMessage(Chat chat, Message message) {
        try
        {
        String from = message.getTo();
        String body = message.getBody();
        String toUser="";
        LOGGER.info(String.format("Received message '%1$s' from %2$s", body, from));
        String[] user=from.split("@");
        for(int i=0;i<user.length;i++)
         toUser=user[0];
        LOGGER.info("Receiver Phone number"+toUser); 
        SendMsgToWhatsapp create=new SendMsgToWhatsapp();
        try {
            if(!body.equalsIgnoreCase(null))
            {
              create.processWhatsappMessage(toUser, body);

            }
        } catch (Exception ex) {
            callThread();

// Logger.getLogger(XmppManager.class.getName()).log(Level.SEVERE, null, ex); } } catch(Exception e) { e.printStackTrace(); callThread(); } }