public static void main ( String  [] args)
	{
		System.out.println("Main Replica B UDP server is up and running ...");
		//multicastListener();
	
		GameUDPServer l_GameUDPServer = new GameUDPServer();
		l_GameUDPServer.start();
		
	 try {
			
			aSocket = new DatagramSocket(Parameters.UDP_PORT_REPLICA_B);
			byte [] buffer = new byte [Parameters.UDP_BUFFER_SIZE];
			
			//always listen for new messages on the specified port
			while (waitForConnection) {							
				
				for ( int i = 0 ; i< messageArray.length;i++) {
					   messageArray[i] = null;
				  }
				dataRecieved = null;
				
				
				DatagramPacket request = new DatagramPacket(buffer, buffer.length);
				aSocket.receive(request);

				//get the data from the request and check
				dataRecieved = new String(request.getData());
				//dataRecieved.toUpperCase();
				messageArray = dataRecieved.split(Parameters.UDP_PARSER);
				
				parserPosition = dataRecieved.indexOf(Parameters.UDP_PARSER);
				System.out.println(dataRecieved);
				
				//get who is initiating the request : RM, Leader, Replica1 or Replica2
				requestServerInitials = messageArray[0];
				requestMethodCode = messageArray[1];
				
				System.out.println("-----------------------------------------------------------");
				System.out.println("Method call for: " + requestMethodCode + " from server : " + requestServerInitials);
				System.out.println("-----------------------------------------------------------");
				int tempIP;
				
				if ((dataRecieved.trim()).contains(Parameters.RB_NAME)) {
					DatagramPacket replayToLeader = new DatagramPacket(request.getData(), request.getLength(),request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
					aSocket.send(replayToLeader);
					System.out.println ("On Main server sent ACK to leader: " +request.getData().toString());
				}
				
				if (!requestMethodCode.contains("1")) {
				if (requestMethodCode.contains(Parameters.METHOD_CODE.RESTART_REPLICA.toString())) {
					//stop the 3 servers
					if (! (replicaNA == null || replicaNA.equals(null))) {
						stopServers();
						//run the 3 UDP servers
						startServers();
					} else {
					//run the 3 UDP servers
					startServers();
					}
				}
				if (requestMethodCode.equalsIgnoreCase(Parameters.METHOD_CODE.CREATE_ACCOUNT.name())) {
					
					//System.out.println("There is a method call for CREATE ACCOUNT");
					tempIP = extractIP(messageArray[7]);
					
					//check the IP if the method is CREATE ACCOUNT
					switch (tempIP) {
					
						case Parameters.NA_IP_ADDRESS : 
							aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_NA, dataRecieved));
							break;
						
						case Parameters.EU_IP_ADDRESS : 
							aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_EU,dataRecieved));
							break;
						
						case Parameters.AS_IP_ADDRESS : 
							aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_AS, dataRecieved));
							break;
							
						default : System.out.println("The IP is not registered in our system");
						break;
					
					}
					//the requested method is PLAYER SIGN IN
					} 
				
				if (requestMethodCode.contains(Parameters.METHOD_CODE.PLAYER_SIGN_IN.name())) {
						tempIP = extractIP(messageArray[4]);
						//check the IP if the method is PLAYER SIGN IN
						switch (tempIP) {
						
							case Parameters.NA_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_NA, dataRecieved));
								break;
							
							case Parameters.EU_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_EU, dataRecieved));
								break;
							
							case Parameters.AS_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_AS, dataRecieved));
								break;
								
							default : System.out.println("The IP is not registered in our system");
							break;
					
						}
						//the requested method is PLAYER SIGN OUT
					} 
				
						if (requestMethodCode.contains(Parameters.METHOD_CODE.PLAYER_SIGN_OUT.name())) {
						tempIP = extractIP(messageArray[3]);
						
						//check the IP if the method is PLAYER SIGN OUT
						switch (tempIP) {
						
							case Parameters.NA_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_NA, dataRecieved));
								break;
							
							case Parameters.EU_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_EU, dataRecieved));
								break;
							
							case Parameters.AS_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_AS,dataRecieved));
								break;
							
							default : System.out.println("The IP is not registered in our system");
							break;
						
						}
						//the requested method is SUSPEND ACCOUNT
					}else if (requestMethodCode.contains(Parameters.METHOD_CODE.SUSPEND_ACCOUNT.name())) {
						tempIP = extractIP(messageArray[4]);
						
						//check the IP if the method is SUSPEND ACCOUNT
						switch (tempIP) {
						
							case Parameters.NA_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_NA, dataRecieved));
								break;
							
							case Parameters.EU_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_EU, dataRecieved));
								break;
							
							case Parameters.AS_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_AS, dataRecieved));
								break;
							
							default : System.out.println("The IP is not registered in our system");
							break;
						
						}
						//the requested method is TRANSFER ACCOUNT
					} else if (requestMethodCode.contains(Parameters.METHOD_CODE.TRANSFER_ACCOUNT.name())) {
						tempIP = extractIP(messageArray[4]);
						
						//check the IP if the method is TRANSFER ACCOUNT
						switch (tempIP) {
						
							case Parameters.NA_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_NA, dataRecieved));
								break;
							
							case Parameters.EU_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_EU,dataRecieved));
								break;
							
							case Parameters.AS_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_AS,dataRecieved));
								break;
						
							default : System.out.println("The IP is not registered in our system");
							break;
						}
					}
					//the requested method is GET PLAYER STATUS
					else if (requestMethodCode.contains(Parameters.METHOD_CODE.GET_PLAYER_STATUS.name())) {
						tempIP = extractIP(messageArray[4]);
						
						//check the IP if the method is  GET PLAYER STATUS
						switch (tempIP) {
						
							case Parameters.NA_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_NA,dataRecieved));
								break;
							
							case Parameters.EU_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_EU, dataRecieved));
								break;
							
							case Parameters.AS_IP_ADDRESS : 
								aSocket.send(forwardUDPMessage(Parameters.UDP_PORT_REPLICA_B_AS,dataRecieved));
								break;
								
							default : System.out.println("The IP is not registered in our system");
							break;
						
						}
					}
					
						//forward the message to the leader
						if (dataRecieved.contains(Parameters.RB_NAME)) {
							DatagramPacket replay = new DatagramPacket(request.getData(), request.getLength(),request.getAddress(),Parameters.UDP_PORT_REPLICA_B);
							//DatagramPacket replay = new DatagramPacket(request.getData(), request.getLength(),request.getAddress(),Parameters.UDP_PORT_REPLICA_LEAD);
							System.out.println("LR will be getting the followinf confirmation: " + replay.getData().toString());
							aSocket.send(replay);
						}
						 
				
		}
			
	 }
	 }
		catch (Exception e) {e.printStackTrace();}

	}