public void onMessage( Message msg ) {
   	 //deal with message from server
   	 try {
   		 msg.acknowledge(); // acknowledge to know that it is already received
   		 String received = ((TextMessage)msg).getText();
   		 
   		 if( registerInProgress ) {
   	       registerInProgress = false;
           System.out.println( "\n" + received );
           /*
           if( received.equals("Your account has been registered.\nYou can now logon and whisper.") ) {
           registerInProgress = false;
           }*/
           return;
         }
   		 
   		 if(received.equals("!loginFailed")){
   			 this.loginInProgress = false;
   			 System.out.println("\n!Login Failed: Username or password is incorrect. ");
   			 return;
   		 }else{
   			 this.user.setOnlineStatus(true);
   			 this.loginInProgress = false;
   						 
   		 }
   		 
   		 //System.out.println(received.substring(0, 8)); //logging
   		 // check if successful server join
   		 if (received.substring(0, 8).equals("!Success")) {
   			 // get the room id in the message
   	   		 System.out.println(received);
   			 String roomid = received.substring(received.indexOf(":") + 2);
   			 // made chatroom
   			 this.makingChatroomCheck = false;
   			 this.completeJoinChatroom(roomid);
   			 return;
   		 }
   		 
   		 // print receive message
   		 System.out.println(received);
   		 if (received.substring(0, 1).equals(">")) {
   			 this.replyTo = received.substring(received.indexOf(" ", 11 ) + 1,
   					 received.indexOf(":"));
   		 }
   	 } catch (JMSException e) {
   		 e.printStackTrace();
   	 }
   	 return;
    }