Ejemplo n.º 1
0
        void OnConnectToServer(object sender, EventArgs e)
        {
            if (mainSock.Connected)
            {
                MsgBoxHelper.Error("이미 연결되어 있습니다!");
                return;
            }
            int port = 15000;    //고정

            nameID = txtID.Text; //ID
            AppendText(txtHistory, string.Format("서버: @{0},port: 15000, ID: @{1}", txtAddress.Text, nameID));

            try
            {
                mainSock.Connect(txtAddress.Text, port);
            }
            catch (Exception ex)
            {
                MsgBoxHelper.Error("연결에 실패했습니다!\n오류 내용: {0}",
                                   MessageBoxButtons.OK, ex.Message);
                return;
            }
            // 연결 완료되었다는 메세지를 띄워준다.
            AppendText(txtHistory, "서버와 연결되었습니다.");


            // 연결 완료, 서버에서 데이터가 올 수 있으므로 수신 대기한다.
            AsyncObject obj = new AsyncObject(4096);

            obj.WorkingSocket = mainSock;
            mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0,
                                  DataReceived, obj);
        }
Ejemplo n.º 2
0
        void BeginStartServer(object sender, EventArgs e)
        {
            int port;

            if (!int.TryParse(txtPort.Text, out port))
            {
                MsgBoxHelper.Error("포트 번호가 잘못 입력되었거나 입력되지 않았습니다.");
                txtPort.Focus();
                txtPort.SelectAll();
                return;
            }
            if (thisAddress == null)
            { // 로컬호스트 주소를 사용한다.
                thisAddress = IPAddress.Loopback;
                //thisAddress = IPAddress.Parse("210.123.255.190");
                txtAddress.Text = thisAddress.ToString();
            }
            else
            {
                thisAddress = IPAddress.Parse(txtAddress.Text);
            }
            // 서버에서 클라이언트의 연결 요청을 대기하기 위해
            // 소켓을 열어둔다.
            IPEndPoint serverEP = new IPEndPoint(thisAddress, port);

            mainSock.Bind(serverEP);
            mainSock.Listen(10);
            AppendText(txtHistory, string.Format("서버 시작: @{0}", serverEP));
            // 비동기적으로 클라이언트의 연결 요청을 받는다.
            mainSock.BeginAccept(AcceptCallback, null);
        }
Ejemplo n.º 3
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            //자기 턴에만 그림을 그릴 수 있어야함.
            if (myturn == true)
            {
                if (reviveFlag == true)
                {
                    ReviveGame();
                    return;
                }

                // e.X는 픽셀단위, x는 바둑판 좌표
                int x = (e.X - margin + 눈Size / 2) / 눈Size;
                int y = (e.Y - margin + 눈Size / 2) / 눈Size;

                if (바둑판[x, y] != STONE.none)
                {
                    return;
                }

                // 바둑판[x,y] 에 돌을 그린다
                Rectangle r = new Rectangle(
                    margin + 눈Size * x - 돌Size / 2,
                    margin + 눈Size * y - 돌Size / 2,
                    돌Size, 돌Size);

                // 검은돌 차례
                if (flag == false)
                {
                    if (imageFlag == false)
                    {
                        g.FillEllipse(bBrush, r);
                    }
                    else
                    {
                        Bitmap bmp = new Bitmap("../../img/black.png");

                        g.DrawImage(bmp, r);
                    }

                    lstRevive.Add(new Revive(x, y, STONE.black, stoneCnt));
                    DrawStoneSequence(stoneCnt++, Brushes.White, r);
                    flag      = true;
                    바둑판[x, y] = STONE.black;
                    OnSendData2(x, y, STONE.black);
                }
                else
                {
                    if (imageFlag == false)
                    {
                        g.FillEllipse(wBrush, r);
                    }
                    else
                    {
                        Bitmap bmp = new Bitmap("../../img/white.png");

                        g.DrawImage(bmp, r);
                    }
                    lstRevive.Add(new Revive(x, y, STONE.white, stoneCnt));
                    DrawStoneSequence(stoneCnt++, Brushes.Black, r);
                    flag      = false;
                    바둑판[x, y] = STONE.white;
                    OnSendData2(x, y, STONE.white);
                }
                myturn = false;
                CheckOmok(x, y);
            }
            else
            {
                MsgBoxHelper.Error("당신의 턴이 아닙니다!");
            }
        }