Exemple #1
0
        private void Button_server_Launch_Click(object sender, EventArgs e)
        {
            var me = (Button)sender;

            if (me.Text == "Stop")
            {
                _listener.Abort();

                _tunnelsHolder.DisableTunnels();

                tabControl1.TabPages.Add(tabPage_client);
                numericUpDown_serverPort.ReadOnly = false;

                me.Text = "Launch";
                GC.Collect();
            }
            else
            {
                try
                {
                    int port     = (int)numericUpDown_serverPort.Value;
                    var endPoint = new IPEndPoint(IPAddress.Any, port);

                    dataGridView1.SuspendLayout();
                    _tunnelsHolder.EnableTunnels();
                    dataGridView1.ResumeLayout();

                    var listener = new Server.Listener(endPoint);
                    listener.Connected    += Listener_Connected;
                    listener.Disconnected += Listener_Disconnected;
                    listener.Listen();
                    _listener = listener;

                    //Server.API.ApiListener.Instance.Enable();

                    me.Text = "Stop";
                    //me.Enabled = false;
                    tabControl1.TabPages.Remove(tabPage_client);
                    numericUpDown_serverPort.ReadOnly = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.GetBaseException().Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }