private void startUDPserver () {
		String globalSystemSat = null;
		
		 try {
				
				aSocket = new DatagramSocket(serverListeningPort);
				byte [] buffer = new byte [Parameters.UDP_BUFFER_SIZE];
				byte [] bufferACK = new byte [Parameters.UDP_BUFFER_SIZE];
				byte [] bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
				
				bufferACK = "1/1".getBytes();
				System.out.println ("Replica " + IPaddress + " is up and running!");
				String methodCall = null;
				
				int statusIndex= 0;
				
				
				//always listen for new messages on the specified port
				while (true) {							
					DatagramPacket request = new DatagramPacket(buffer, buffer.length);
					aSocket.receive(request);
					dataRecieved = (new String(request.getData()).trim());
					System.out.println("Data recieved at GEO server " + dataRecieved);
					
					if (dataRecieved.contains("online")) {
						statusIndex =  dataRecieved.indexOf("online");
						dataRecieved = dataRecieved.substring(0,statusIndex);
						methodAcknowledgmentStr.concat((dataRecieved));
						
						globalSystemSat = globalSystemSat.concat(dataRecieved);
						globalSystemSat = globalSystemSat.replace("//", "/");
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						bufferStat = ("RB/1" + Parameters.UDP_PARSER + Parameters.RB_NAME + globalSystemSat  + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();						
						
						DatagramPacket replay3 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
						aSocket.send(replay3);
						log (globalSystemSat);
						System.out.println(globalSystemSat);
					}
					
					if (!dataRecieved.contains(Parameters.REQUEST_LOCAL_STAT)) {
					messageArray = dataRecieved.split(Parameters.UDP_PARSER);
					//Extract the method forwarded from the main UDP server					
					methodCall = messageArray[1];
					} else  {
						methodCall = Parameters.REQUEST_LOCAL_STAT;
					}
					
					if (methodCall.contains(Parameters.METHOD_CODE.CREATE_ACCOUNT.name())) {
						System.out.println("Inside method on the local server CREATE_ACCOUNT");
						//call create account
						methodAcknowledgment =  createPlayerAccount(messageArray[2], messageArray[3], Integer.parseInt(messageArray[4]), messageArray[5], messageArray[6], messageArray[7]);
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						if (methodAcknowledgment == true) {
							bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "1" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();						
							
						} else  { bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "0"  + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();	}
						
						DatagramPacket replay3 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
						aSocket.send(replay3);
					}
					else if (methodCall.contains(Parameters.METHOD_CODE.PLAYER_SIGN_IN.name())){
						System.out.println("Inside method on the local server SIGN IN");
						//call player sign in
						methodAcknowledgment =  PlayerSignIn(messageArray[2], messageArray[3], messageArray[4]);
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						if (methodAcknowledgment == true) {
							bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "1"  + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();						
							
						} else  { bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "0"  + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();	}
						
						DatagramPacket replay3 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
						aSocket.send(replay3);
					} 
					else if (methodCall.contains(Parameters.METHOD_CODE.PLAYER_SIGN_OUT.name())){
						
						//call player sign out
						methodAcknowledgment =  PlayerSignOut(messageArray[2], messageArray[3]);
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						if (methodAcknowledgment == true) {
							bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "1" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();						
							
						} else  { bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "0" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();	}
						
						DatagramPacket replay3 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
						aSocket.send(replay3);
						
					} 
					else if (methodCall.contains(Parameters.METHOD_CODE.SUSPEND_ACCOUNT.name())){
						
						//call suspend account
						methodAcknowledgment = suspendAccount(messageArray[2], messageArray[3], messageArray[4], messageArray[5]);
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						if (methodAcknowledgment == true) {
							bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "1" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();						
							
						} else  { bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + Parameters.UDP_PARSER + "0" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();	}
						
						DatagramPacket replay3 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
						aSocket.send(replay3);
						
					} else if (methodCall.contains(Parameters.METHOD_CODE.TRANSFER_ACCOUNT.name())){
						if (!(dataRecieved.contains(Parameters.TRANSFER_DONE) || dataRecieved.contains(Parameters.TRANSFER_FAIL)))
						{
						
						
						//call transfer account
						methodAcknowledgmentStr = transferAccount(messageArray[2], messageArray[3], messageArray[4], messageArray[5]);
						if (!(methodAcknowledgmentStr.equals(null) || methodAcknowledgmentStr == null ))
						{
							bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
							bufferStat = (Parameters.REQUEST_LOCAL_TRANSFER + Parameters.UDP_PARSER + methodAcknowledgmentStr).getBytes();
							DatagramPacket replay6 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),getPortPerIP(messageArray[5]));
							aSocket.send(replay6);
							System.out.println("Init transfer " + new String(replay6.getData()));
							log("Request for account transfer is initiated");
						}
						}
						
						
					} else if (methodCall.contains(Parameters.METHOD_CODE.GET_PLAYER_STATUS.name())){
						System.out.println("GET_PLAYER_STATUS is requested!");
						//call get player status
						methodAcknowledgmentStr = getPlayerStatus(messageArray[2], messageArray[3], messageArray[4]);
					//send 2 UDP messages to the other 2 servers	
							
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];	
						bufferStat = (Parameters.REQUEST_LOCAL_STAT).getBytes();						
						DatagramPacket replay1 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),LOCAL_CONNECTION_1);
						aSocket.send(replay1);
						DatagramPacket replay2 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),LOCAL_CONNECTION_2);
						aSocket.send(replay2);
						//methodAcknowledgmentStr = methodAcknowledgmentStr.replace("//", "/");
						log (methodAcknowledgmentStr);
						
						System.out.println (methodAcknowledgmentStr);
						
						statusIndex =  methodAcknowledgmentStr.indexOf("online");
						methodAcknowledgmentStr = methodAcknowledgmentStr.substring(0,statusIndex-1);
						globalSystemSat = methodAcknowledgmentStr;
						
						
					} else if (dataRecieved.contains(Parameters.REQUEST_LOCAL_STAT)) {
						if(!dataRecieved.contains("/")){
						//	buffer = null;
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						bufferStat = getPlayerStatus("Admin", "Admin",String.valueOf(IPaddress)).getBytes();						
						DatagramPacket replay3 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),request.getPort());
						aSocket.send(replay3);
						System.out.println ("The METHOD CODE  REQUEST_LOCAL_STAT is sent to "  +request.getPort() + "  the data sent follow:" + getPlayerStatus("Admin", "Admin",String.valueOf(IPaddress)));
						log ("Local stat is requested : " + getPlayerStatus("Admin", "Admin",String.valueOf(IPaddress)));
						}
					} 
					
					if (dataRecieved.contains(Parameters.REQUEST_LOCAL_TRANSFER)){
						System.out.println("REQUEST_LOCAL_TRANSFER is requested!");
						//call get player status
						methodAcknowledgment = createPlayerAccount(messageArray[2], messageArray[3], Integer.parseInt(messageArray[4]), messageArray[5], messageArray[6], String.valueOf(IPaddress) + ".");
					//send 2 UDP messages to the other 2 servers	
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];	
						if (methodAcknowledgment == true) {
							bufferStat = (Parameters.TRANSFER_DONE + Parameters.UDP_PARSER + messageArray[5] + Parameters.UDP_PARSER + "1" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();						
							
						} else  { bufferStat = (Parameters.TRANSFER_FAIL + Parameters.UDP_PARSER + "0" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();	}
						
						DatagramPacket replay3 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),request.getPort());
						System.out.println("To send acc for the transfer " + new String( replay3.getData()));
						aSocket.send(replay3);
						
					
					}else 
					if (dataRecieved.contains(Parameters.TRANSFER_DONE)) {
						suspendAccount("Admin", "Admin", String.valueOf(IPaddress) + ".", messageArray[1]);
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "1" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();						
						DatagramPacket replay5 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
						aSocket.send(replay5);
						System.out.println("Transfer done, ACK sent " + new String(replay5.getData()));
					} else 
							
					if (dataRecieved.contains(Parameters.TRANSFER_FAIL)){
						bufferStat = new byte [Parameters.UDP_BUFFER_SIZE];
						bufferStat = (Parameters.RB_NAME + Parameters.UDP_PARSER + "0" + Parameters.UDP_PARSER + Parameters.UDP_END_PARSE).getBytes();
						 DatagramPacket replay5 = new DatagramPacket(bufferStat, bufferStat.length,request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
						aSocket.send(replay5);	
						System.out.println("Transfer failed, NACK sent " + new String(replay5.getData()));
						
					}
				}			
		 }
			catch (Exception e) {e.printStackTrace();}

	}