static void Main(string[] args) { // defaults ushort FTSERVER_PORT = 40000; int CLIENT_BACKLOG = 5; string PRS_ADDRESS = "127.0.0.1"; ushort PRS_PORT = 30000; string SERVICE_NAME = "FT Server"; // process the command line arguments to get the PRS ip address and PRS port number try { if (args.Length > 0) { if (args[0] == "-prs") { string[] IP_PORT = args[1].Split(':'); PRS_ADDRESS = IP_PORT[0]; PRS_PORT = ushort.Parse(IP_PORT[1]); } } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); Console.WriteLine(ex.StackTrace); } Console.WriteLine("PRS Address: " + PRS_ADDRESS); Console.WriteLine("PRS Port: " + PRS_PORT); try { // contact the PRS, request a port for "FT Server" and start keeping it alive PRSClient prs = new PRSClient(PRS_ADDRESS, PRS_PORT, SERVICE_NAME); FTSERVER_PORT = prs.RequestPort(); prs.KeepPortAlive(); // instantiate FT server and start it running FTServer ft = new FTServer(FTSERVER_PORT, CLIENT_BACKLOG); ft.Start(); // tell the PRS that it can have it's port back, we don't need it anymore prs.ClosePort(); } catch (Exception ex) { Console.WriteLine("Error " + ex.Message); Console.WriteLine(ex.StackTrace); } // wait for a keypress from the user before closing the console window Console.WriteLine("Press Enter to exit"); Console.ReadKey(); }
static void Main(string[] args) { // TODO: SDServerProgram.Main() // defaults ushort SDSERVER_PORT = 40000; int CLIENT_BACKLOG = 5; string PRS_ADDRESS = "127.0.0.1"; ushort PRS_PORT = 30000; string SERVICE_NAME = "SD Server"; // process the command line arguments to get the PRS ip address and PRS port number Console.WriteLine("PRS Address: " + PRS_ADDRESS); Console.WriteLine("PRS Port: " + PRS_PORT); try { // contact the PRS, request a port for "FT Server" and start keeping it alive PRSClient prs = new PRSClient(PRS_ADDRESS, PRS_PORT, SERVICE_NAME); SDSERVER_PORT = prs.RequestPort(); prs.KeepPortAlive(); // instantiate SD server and start it running SDServer sd = new SDServer(SDSERVER_PORT, CLIENT_BACKLOG); sd.Start(); // tell the PRS that it can have it's port back, we don't need it anymore prs.ClosePort(); } catch (Exception ex) { Console.WriteLine("Error " + ex.Message); Console.WriteLine(ex.StackTrace); } // wait for a keypress from the user before closing the console window Console.WriteLine("Press Enter to exit"); Console.ReadKey(); }
static void Main(string[] args) { // defaults ushort SDSERVER_PORT = 40000; int CLIENT_BACKLOG = 5; string PRS_ADDRESS = "127.0.0.1"; ushort PRS_PORT = 30000; string SERVICE_NAME = "SD Server"; for (int i = 0; i < args.Length; i++) { var arg = args[i]; switch (arg) { case "-prs": { var parameters = args[++i].Split(':'); var ipAddress = parameters[0]; var port = parameters[1]; PRS_ADDRESS = ipAddress; PRS_PORT = ushort.Parse(port); } break; default: { Console.WriteLine($"Invalid argument: {arg}"); Usage(); } break; } } Console.WriteLine("PRS Address: " + PRS_ADDRESS); Console.WriteLine("PRS Port: " + PRS_PORT); try { // contact the PRS, request a port for "FT Server" and start keeping it alive var prs = new PRSClient(PRS_ADDRESS, PRS_PORT, SERVICE_NAME); SDSERVER_PORT = prs.RequestPort(); prs.KeepPortAlive(); // instantiate SD server and start it running var server = new SDServer(SDSERVER_PORT, CLIENT_BACKLOG); server.Start(); // tell the PRS that it can have it's port back, we don't need it anymore prs.ClosePort(); } catch (Exception ex) { Console.WriteLine("Error " + ex.Message); Console.WriteLine(ex.StackTrace); } // wait for a keypress from the user before closing the console window Console.WriteLine("Press Enter to exit"); Console.ReadKey(); }
static void Main(string[] args) { // defaults ushort FTSERVER_PORT = 40000; int CLIENT_BACKLOG = 5; string PRS_ADDRESS = "127.0.0.1"; ushort PRS_PORT = 30000; string SERVICE_NAME = "FT Server"; // process the command line arguments to get the PRS ip address and PRS port number for (var i = 0; i < args.Length; i++) { var arg = args[i]; switch (arg) { case "-prs": { var prs = args[++i].Split(':'); PRS_ADDRESS = prs[0]; PRS_PORT = ushort.Parse(prs[1]); } break; default: { Console.WriteLine($"Invalid argument: {arg}"); Usage(); return; } } } Console.WriteLine("PRS Address: " + PRS_ADDRESS); Console.WriteLine("PRS Port: " + PRS_PORT); try { // contact the PRS, request a port for "FT Server" and start keeping it alive var prsClient = new PRSClient(PRS_ADDRESS, PRS_PORT, SERVICE_NAME); FTSERVER_PORT = prsClient.RequestPort(); prsClient.KeepPortAlive(); Console.WriteLine($"Received port {FTSERVER_PORT} from PRS Server"); // instantiate FT server and start it running Console.WriteLine("Starting FT server"); var ftServer = new FTServer(FTSERVER_PORT, CLIENT_BACKLOG); ftServer.Start(); Console.WriteLine($"FT server stopped"); // tell the PRS that it can have it's port back, we don't need it anymore prsClient.ClosePort(); Console.WriteLine("FT server port closed"); } catch (Exception ex) { Console.WriteLine("Error " + ex.Message); Console.WriteLine(ex.StackTrace); } // wait for a keypress from the user before closing the console window Console.WriteLine("Press Enter to exit"); Console.ReadKey(); }