void* MessageHandler::run(void* data) {
	MessageHandler *ml = (MessageHandler*) data;
	Message *message=&ml->incomingMessage;
	ml->message=ml->incomingMessage;
	MessageCreator *mcreator=new MessageCreator();

	json::Object json;
	try {
		if(message->header==mcreator->H_DECLARATION){

			if(!ml->isUserIPAvailable(message->fromIP)){
				ml->addNewUser(message->fromIP);
				//MESSAGE:{"HEADER:","CONTENT:",USERLIST:{}}
				mcreator->preapareUserList(json);
				//mcreator->createMessage(mcreator->H_USERLIST,json,"","");
				ml->sendMessageToUser(message->fromIP,	mcreator->createMessage(mcreator->H_USERLIST,json,"",""));
			}else{
				//MESSAGE:{"HEADER:ERROR","CONTENT:",USERLIST:{}}
				ml->sendMessageToUser(message->fromIP,	mcreator->createMessage(mcreator->H_USERLIST,json,"",""));

				//ml->sendMessageToUser(message->fromIP,mcreator->createMessage(mcreator->H_ERROR,mcreator->NODATA,"",""));
			}

		}else if(message->header==mcreator->H_MESSAGETOUSER){
			if(ml->isUserIPAvailable(message->toIP)){
				//MESSAGE is user message//std::string DECLERATION="DECLERATION";
				//std::string MESSAGETOUSER="******";
				//std::string UPDATE="UPDATE";
				ml->sendMessageToUser(message->toIP,mcreator->createMessage(mcreator->H_MESSAGETOUSER,message->message,message->fromIP,message->toIP));

			}else{
				//ERRORMESSAGE=User isn't available anymore!
				ml->sendMessageToUser(message->fromIP,mcreator->createMessage(mcreator->H_ERROR,mcreator->USERNOTAVAILABLE,"",""));
			}
		}else if(message->header==mcreator->H_UPDATE){
			bool success=false;
			//ERRORMESSAGE: This message couldn't be recognized by our system!
			if(ml->isUserIPAvailable(message->fromIP)){
				success=ml->updateUserTimeoutDuration(message->fromIP);
			}
			if(success){
				//MESSAGE:{"HEADER:","CONTENT:",USERLIST:{}}
				ml->sendMessageToUser(message->fromIP,	mcreator->createMessage(mcreator->H_USERLIST,json,"",""));
			}else{
				//MESSAGE:{"HEADER:ERROR","CONTENT:",USERLIST:{}}
				ml->sendMessageToUser(message->fromIP,mcreator->createMessage(mcreator->H_ERROR,mcreator->NODATA,"",""));
			}
		}else{
			ml->sendMessageToUser(message->fromIP,mcreator->createMessage(mcreator->H_ERROR,mcreator->MESSAGEUNKNOWN,"",""));
		}
		delete mcreator;
		Utilities::writeConsole(" Check connectivity");
		//sleep(updateDuration);
	}  catch (std::exception& e) {
		std::cerr<<className  << e.what() << std::endl;
	}
	pthread_exit(NULL);

}