public PRSMessage ParseMessageType(PRSMessage Request)//Parses through message and formulates a response to be sent back { //error checking //0. SUCCESS //1.SERVICE_IN_USE //2.SERVICE_NOT_FOUND //3.ALL_PORTS_BUSY //4.INVALID_ARG //5.UNDEFINED_ERROR try { switch (Request.msgType)//checks the type { case PRSMessage.MsgType.PORT_DEAD: return(portdead(Request)); case PRSMessage.MsgType.CLOSE_PORT: //Closes the requested port 3 errors 2,4,5 //if service in msg is not at either the correct port or name //throw out Response service not found return(close_port(Request)); case PRSMessage.MsgType.KEEP_ALIVE: //keeps service alive 3 errors 2,4,5 //if port or service is incorrect return invalid return(keep_alive(Request)); case PRSMessage.MsgType.LOOKUP_PORT: //takes a service name and gives a port error 2,4,5 //if not well formulated throw invalid //if service name not correct return not found return(lookup_port(Request)); case PRSMessage.MsgType.REQUEST_PORT: //Gives service lowest port 1,3,4,5 return(request_port(Request)); case PRSMessage.MsgType.STOP: //Server gets stopped by the Handler this sends response //only checks message type Console.WriteLine("Stop Has been recieved"); return(PRSMessage.MakeSTOP()); //Stop doesn't impact the port reservations so it just uses its method default: //if not a correct message code return(PRSMessage.MakeRESPONSE(PRSMessage.Status.INVALID_ARG, 0)); //Returns an invalid arg } } catch (Exception e) { return(PRSMessage.MakeRESPONSE(PRSMessage.Status.UNDEFINED_ERROR, 0));//if this happened the service broke } }
private static void StopServer(Socket clientsocket) { IPEndPoint endPt = new IPEndPoint(IPAddress.Parse(PRSCommunicator.DEFAULT_IP), PRSCommunicator.DEFAULT_PORT); PRSCommunicator.SendMessage(clientsocket, endPt, PRSMessage.MakeSTOP()); }