static void Main(string[] args) { //Launch Our App (Server or Client) int numberOfArgs = args.Length; Driver driver = new Driver(); //Create an instance of the driver switch (numberOfArgs) { case 1: { if (args[0] == SERVERFLAG) { //If arg is -server NetworkingThings server = new Server(); //Create an Istance of the server while (true) { //While True, Keep checking for for client to connect Console.Write("Waiting for Connection..."); server.Listen(); //Waits for the Client to Connect. Console.WriteLine("Connected"); Console.WriteLine(); driver.Drive(server); //Runs the Driver } } else { //If its any arg thats not -server or -client Console.WriteLine("Invalid Argument"); } break; } default:{ //If there isn't an arg. NetworkingThings client = new Client(); //Create an Instance of Client if (client.Listen()) { //If it can connect to the server Console.WriteLine("Connected to the Server"); Console.WriteLine(); driver.Drive(client); //Runs the Driver } else { //State that it can't Connect Console.WriteLine("Unable to connect to Server. Please try again later."); } break; } } #if DEBUG Console.Read(); #endif }
/// <summary> /// Starts the server /// </summary> /// <param name="args"></param> static void Main(string[] args) { Server server = new ChatLib.Server(); server.StartUpServer(); if (server.Started()) { Console.Write("Waiting for connection..."); //wait for a connection from the client server.FindConnection(); Console.WriteLine("Client Received!"); Console.WriteLine(); ServerChat(server); } }