예제 #1
0
 /// <summary>
 /// constructor for the client form
 /// Instantiates the inner tcpClient, then sets up all event handlers.
 /// </summary>
 public ui()
 {
     client = new Client();
     //Initialize all event handlers for the UI
     client.MessageReceived += new MessageHandler(SendOrReceiveMessage);
     client.MessageSent += new MessageHandler(SendOrReceiveMessage);
     client.Connected += new ConnectHandler(Connect);
     client.Disconnected += new DisconnectHandler(Disconnect);
     InitializeComponent();
 }
예제 #2
0
        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
        }