OverviewIn this project you will implement a server for the Purdue Safe Walk Program. The server you are going to write will handle requests and commands sent from the user.Safe Walk is a campus safety system (currently done manually) that allows people on campus to request that someone walk with them from one location to another on campus. For more details, refer to this document.DefinitionsHere are some definitions and terms that will be used throughout this project.LocationsA location is a building in Purdue campus. A location is identified by a unique acronym. First, for simplicity, the following locations will be defined in the system:CL50: Class of 1950 Lecture HallEE: Electrical Engineering BuildingLWSN: Lawson Computer Science BuildingPMU: Purdue Memorial UnionPUSH: Purdue University Student Health Center*: Any one of the location aboveYou may think of * as a wildcard that matches with any of the first five locations.As you will see later, a user message will contain two locations, FROM and TO. Locations not on the list above will be considered invalid.UserA user is anyone who sends content to the server.RequesterA requester is a user who asks for help (instead of sending commands). Again, as you will find later, not all users are requesters.PrerequisitesKnowledge of file I/O operations.Knowledge of Java List API.ObjectivesUnderstand and use the Java Socket API to implement an iterative server.More specifically, java.net.ServerSocket for a socket-based server program.Understand the similarities between files and sockets.Learn to implement a basic, text-based server-client protocol.Learn to write exhaustive JUnit tests.Learn to use simple network utilities telnet and netcat (nc).SpecificationsNow you are going to write your own server program.Command-Line ArgumentsName your program SafeWalkServer. To run it, use the command java SafeWalkServer port where the port argument should be an integer between1025 and 65535 inclusive. If the port argument is given but invalid, print an error message (any meaningful message) and exit gracefully. If the port argument is not provided, your program should use a port that is automatically allocated, in which case you must print this port number to stdout before the server startsaccepting requests. For example,Port not specified. Using free port 8888.where 8888 is the port allocated automatically. Note that 8888 is just an example.If the port is already used (the constructor of ServerSocket will throw an exception). Print an error message and exit gracefully.Class ConstructorsYour SafeWalkServer should have two constructors corresponding to the situations where port may or may not be given.Finish these two methods:/**
* Construct the server, and create a server socket,
* bound to the specified port.
*
* @throws IOException IO error when opening the socket.
*/
public SafeWalkServer(int port) throws IOException {
//TODO: finish the method
}
/**
* Construct the server, and create a server socket,
* bound to a port that is automatically allocated.
*
* @throws IOException IO error when opening the socket.
*/
public SafeWalkServer() throws IOException {
//TODO: finish the method
}Note that the constructors may throw exceptions if any problem occurs during the execution of the constructor. If the object is successfully instantiated without exceptions then the server object is ready to run.To enable the socket to be reclaimed by the operating system when the program exits, be sure to set the address to reusable by callingsetReuseAddress(true). For more details, refer to setReuseAddress.Required MethodsYour SafeWalkServer class must extend ServerSocket class and implement the Run
nable interface. Thus, you must provide a run method. You must also provide a method isPortValid. The following javadoc comments describe their functionality./**
* Start a loop to accept incoming connections.
*/
public void run() {
//TODO: finish this method
}
/**
* Return true if the port entered by the user is valid. Else return false.
* Return false if you get a NumberFormatException while parsing the parameter port
* Call this method from main() before creating SafeWalkServer object
* Note that you do not have to check for validity of automatically assigned port
*/
public static boolean isPortValid(String port) {
//TODO: finish this method
}Note that your server should not start accepting incoming requests before run() is called.To make the server run forever, your run() method may look something like:while (/* condition */) {
Socket client = accept();
// i.e., do something with client
}Note that accept() blocks the execution of the server until there is an incoming connection.Basic ProtocolIt is very difficult for two people to communicate if one does not understand the others language. Similarly, a server cannot talk to clients unless they conform to the same protocol. The protocol that your server uses will be simple text messages.Client RequestsThere are two types of messages that your server needs to handle: request messages and commands.The request message is simple text in CSV (comma-separated value) form, with three fields: NAME,FROM,TO whereNAME is the human-friendly name of the user. You can assume it does not contain any commas.FROM is the location the user wants to move from (FROM cannot be *).TO is the destination of the users movement (TO cannot be the same as FROM).For example, a message Tom Riddle,LWSN,PUSH means the person named Tom Riddle wants to move from LWSN to PUSH, while the message Harry Potter,LWSN,* means that Harry Potter wants to move from LWSN to * location (perhaps to help someone as a volunteer).There are three commands that your server needs to handle. Note that they all start with a colon (:).:RESETFor each waiting request message, respond with ERROR: connection reset and close its socket, before discarding the request.For the client that originated the command, respond with RESPONSE: success and close its socket.:SHUTDOWNGracefully terminate the server (i.e., do what :RESET does, close the socket and whatever streams your server uses, and exit the run loop).:PENDING_REQUESTS,TASK,FROM,TOTASK refers to the information that the user is seeking. Valid values for TASK are # and *.Valid values for FROM and TO are one of the locations listed above.Refer to the following table to know the action that needs to performed for each combination of TASK, FROM and TO. Close the client socket after the write operation. While writing unpaired request messages, use the 3-tuple form (see example below)If a command from the client starts with a colon (:) but does not conform to the above specifications then respond to the client with ERROR: invalid command and close its socket.TASKFROMTOWrite to the client socket (Action)#**total number of pending requests#Any valid location other than **total number of pending requests starting at FROM#*Any valid location other than *total number of pending requests destined to TO***list all the pending requestsExample commands and their corresponding response messages are as shown below. Note that these are examples, you should not hard code values in your program. You should stick to the format of the response messages shown below.:PENDING_REQUESTS,#,LWSN,* // command
RESPONSE: # of pending requests from LWSN = 1 // response