Beispiel #1
0
        private void Create_Server_Click(object sender, EventArgs e)
        {
            host            = new PlayHold_em_host(this);
            mainSock        = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            host.Pname      = textBox1.Text;
            host.money      = int.Parse(textBox2.Text);
            host.ante       = int.Parse(textBox3.Text);
            host.startmoney = int.Parse(textBox2.Text);
            host.Pnames.Add(textBox1.Text);
            int port;

            if (!int.TryParse(PORT.Text, out port))
            {
                MessageBox.Show("포트 번호가 잘못 입력되었거나 입력되지 않았습니다.");
                PORT.Focus();
                PORT.SelectAll();
                return;
            }

            //클라이언트 연결 요청을 위해 소켓 오픈
            IPEndPoint serverEP = new IPEndPoint(thisAddress, port);

            mainSock.Bind(serverEP);
            mainSock.Listen(10);

            mainSock.BeginAccept(host.AcceptCallback, null);

            host.Show();
            this.Hide();
        }
Beispiel #2
0
        private void Enter_Server_Click(object sender, EventArgs e)
        {
            mainSock     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            client       = new PlayHold_em_client(this);
            client.Pname = textBox1.Text;
            client.money = int.Parse(textBox2.Text);
            if (mainSock.Connected)
            {
                MessageBox.Show("이미 연결되어 있습니다!");
                return;
            }

            int port;

            if (!int.TryParse(PORT.Text, out port))
            {
                MessageBox.Show("포트 번호가 잘못 입력되었거나 입력되지 않았습니다.");
                PORT.Focus();
                PORT.SelectAll();
                return;
            }

            try { mainSock.Connect(IP.Text, port); }
            catch (Exception ex)
            {
                MessageBox.Show("연결에 실패했습니다!\n오류 내용: {0}", ex.Message);
                return;
            }

            AsyncObject obj = new AsyncObject(4096);

            obj.WorkingSocket = mainSock;
            mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0, client.DataReceived, obj);

            //MessageBox.Show("서버에 입장 중입니다.");
            client.Show(); //클라이언트창오픈
            this.Hide();
        }