Example #1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            bool isConnect = true;

            tbxReceivedData.Text = "";
            try
            {
                tbxLocalIpAddress.Text =
                    Regex.Replace(tbxLocalIpAddress.Text, @"[^0-9].[^0-9].[^0-9].[^0-9]", "");
                tbxPort.Text = Regex.Replace(tbxPort.Text, @"[^0-9]", "");
                if (tbxLocalIpAddress.Text == "" || tbxPort.Text == "")
                {
                    throw new Exception();
                }

                if (isConnect)
                {
                    IPAddress  serverIPAddress = IPAddress.Parse(tbxLocalIpAddress.Text.Trim());
                    IPEndPoint serverEndPoint  = new IPEndPoint(serverIPAddress, Int32.Parse(tbxPort.Text));
                    _connectSocket = serverEvent.SetupSocket();
                    _connectSocket.Bind(serverEndPoint);
                    _connectSocket.Listen(1);

                    ThreadStart threadDelegate = new ThreadStart(ReceiveDataThread);
                    Thread      playThread     = new Thread(threadDelegate);
                    playThread.Start();
                }
            }
            catch
            {
                MessageBox.Show("Local IP Address 또는 Port 번호가 올바르지 않습니다.");
                isConnect = false;
            }
            if (isConnect == true)
            {
                ButtonStatusChange();
            }
        }