void ButtonStartListenClick(object sender, System.EventArgs e)
        {
            WriteLogPri("Starting listening.....");
            login = 0;
            frmLogin frm = new frmLogin();
            frm.ShowDialog();
            if (login == 0)
                return;
            string portNumber = "8099";
            try
            {
                textBoxMsg.Text = "Listening";
                // Check the port value
                if (textBoxPort.Text == "")
                {
                    MessageBox.Show("Please enter a Port Number");
                    return;
                }
                string portStr = portNumber;
                int port = System.Convert.ToInt32(portStr);
                // Create the listening socket...
                m_mainSocket = new Socket(AddressFamily.InterNetwork,
                    SocketType.Stream,
                    ProtocolType.Tcp);
                IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
                // Bind to local IP Address...
                m_mainSocket.Bind(ipLocal);
                // Start listening...
                m_mainSocket.Listen(4);
                // Create the call back for any client connections...
                m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);

                UpdateControls(true);

                //Start thread for process
                timer1.Enabled = true;

                ThreadArray.Add("-");
                ThreadArray.Add("-");
                ThreadArray.Add("-");
                //End thread for process
                WriteLogPri("Finished listening!!!");

            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }

        }
Пример #2
0
 void ButtonStopListenClick(object sender, System.EventArgs e)
 {
     login = 0;
     frmLogin frm = new frmLogin();
     frm.ShowDialog();
     if (login == 0)
         return;
     textBoxMsg.Text = "Stoped";
     CloseSockets();
     UpdateControls(false);
     timer1.Enabled = false;
     UpdateClientListControl();
     Application.Exit();
 }