/// <summary>
        /// Below is where the connection button for the
        /// chat server will take place once the button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listenButton_Click(object sender, EventArgs e)
        {
            try
            {

                isListening = !isListening;

                if (isListening)
                {
                    ipAddr = IPAddress.Parse(txtIp.Text);
                    mainServer = new ChatServer(ipAddr);

                    // Hook the StatusChanged event handler to mainServer_StatusChanged
                    ChatServer.StatusChanged += new StatusChangedEventHandler(mainServer_StatusChanged);

                    // Start listening for connections
                    mainServer.StartListening();

                    // Show that we started to listen for connections
                    txtIp.Enabled = true;
                    txtLog.Enabled = true;
                    txtLog.AppendText("Monitoring for connections...\n\n");     //checks for connection
                    listenButton.Text = "Stop Listening";                       //changes once the button is clicked
                }

                else if (listenButton.Text == "Stop Listening")                  //vice versa
                {
                    txtIp.Enabled = false;
                    txtLog.Enabled = false;
                    txtLog.AppendText("...No longer listening\n\n");            //signals that it is no longer connecting
                    listenButton.Text = "Start Listening";
                    mainServer.StopListening();
                    Thread.CurrentThread.Abort();
                    ChatServerWindow.ActiveForm.Dispose();                      //closes the form
                    ChatServerWindow.ActiveForm.Close();

                    this.Close();//closes the form
                }

                //else if (listenButton.Text == "Start Listening")                //basically repeats the process by reconnecting.
                //{

                //    txtIp.Enabled = true;
                //    txtLog.Enabled = true;
                //    txtLog.AppendText("Monitoring for connections...\n\n");
                //    listenButton.Text = "Stop Listening";
                //}
            }
            catch (Exception error)
            {

            }

            //MulticastIP();
        }
Beispiel #2
0
 public static void Main()
 {
     ChatServer c = new ChatServer();
 }