Exemple #1
0
        private void Connect()
        {
            if (sck != null)
            {
                sck.Close();
            }
            sck                 = new SocketMangaer();
            sck.IP              = txbIP.Text;
            sck.PORT            = (int)txtPort.Value;
            this.statusBar.Text = "processing....";
            Thread thread = new Thread(() =>
            {
                btnLan.Enabled       = false;
                btnDiconnect.Enabled = true;
                if (!sck.ConnectServer())
                {
                    bool kq = true;
                    sck.CreateServer(out kq);

                    if (kq == true)
                    {
                        if (!otherPlayQuit)
                        {
                            this.statusBar.Text = "you are server";
                        }
                        else
                        {
                            this.statusBar.Text = "other player is quit ";
                        }
                        this.FirstPlay = true;
                        otherPlayQuit  = false;


                        Thread listenThread = new Thread(() =>
                        {
                            while (true)
                            {
                                try
                                {
                                    SocketData data = (SocketData)sck.ReceiveData();
                                    ProcessData(data);

                                    if (btnServerFirst.Checked)
                                    {
                                        sck.SendData(new SocketData((int)SocketCommand.FIRSTPLAY, "1", null));

                                        this.FirstPlay = true;
                                    }
                                    else
                                    {
                                        sck.SendData(new SocketData((int)SocketCommand.FIRSTPLAY, "2", null));

                                        this.FirstPlay = false;
                                    }
                                    break;
                                }
                                catch
                                {
                                }
                            }
                        });
                        listenThread.IsBackground = true;
                        listenThread.Start();
                    }
                    else
                    {
                        this.statusBar.Text = "cant connect pls check your port";
                    }
                }
                else
                {
                    this.Invoke(new control(clientUI));
                    Listen();

                    sck.SendData(new SocketData((int)SocketCommand.PLAYER_NAME, txbPlayerName.Text, null));
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }
Exemple #2
0
        private void ChessBroad_PlayerMarked(object sender, ButtonClickEvent e)
        {
            sck.SendData(new SocketData((int)SocketCommand.SEND_POINT, null, e.ClickPoint));
            panelChessBroad.Enabled = false;
            pcbCoolDown.Value       = 0;
            timerCoolDown.Start();

            Listen();
        }