Example #1
0
        private void BeginReceiveCallback(IAsyncResult ar)
        {
            // get the client socket
            TcpClient client    = (TcpClient)ar.AsyncState;
            int       bytesRead = client.Client.EndReceive(ar);

            string message = System.Text.Encoding.ASCII.GetString(_buffer, 0, bytesRead);

            Receive();

            if (message.Contains("GAMEQB"))
            {
                ThreadHelper.Hide(this);
                //this.Hide();//kaipuhn muna ithread
                GameType = "QB";
                // GameRules GR = new GameRules();
                //  GR.ShowDialog();

                //  testing GR = new testing();
                GameParticipant GR = new GameParticipant();
                GR.ShowDialog();
            }

            else if (message.Contains("GAMEPZ"))
            {
                ThreadHelper.Hide(this);

                //this.Hide();//kaipuhn muna ithread
                GameType = "PZ";
                //  GameRules GR = new GameRules();
                // GR.Show();


                GameParticipant GR = new GameParticipant();
                GR.ShowDialog();
            }



            //client.Client.Shutdown(SocketShutdown.Both);
            //client.Client.Close();


            else
            {
                ThreadHelper.lsbAddItem(this, lsbWait, message);
                Receive();
            }
        }
        private void BeginReceiveCallback(IAsyncResult ar)
        {
            try
            {
                // get the client socket
                TcpClient client    = (TcpClient)ar.AsyncState; ///error forcibly close
                int       bytesRead = client.Client.EndReceive(ar);

                string message = System.Text.Encoding.ASCII.GetString(_buffer, 0, bytesRead);

                Receive();

                if (message.Contains("CONFIRM"))
                {
                    ThreadHelper.lsbAddItem(this, lsbWait, " You are now connected! Please Wait");
                }

                else if (message.Contains("GAMEIPQB"))
                {
                    ThreadHelper.Hide(this);
                    //this.Hide();//kaipuhn muna ithread
                    GameType = "QB";
                    // GameRules GR = new GameRules();
                    //  GR.ShowDialog();

                    //  testing GR = new testing();
                    GameParticipant GR = new GameParticipant();
                    GR.ShowDialog();
                }

                else if (message.Contains("GAMEIPPZ"))
                {
                    ThreadHelper.Hide(this);

                    //this.Hide();//kaipuhn muna ithread
                    GameType = "PZ";
                    //  GameRules GR = new GameRules();
                    // GR.Show();


                    GameParticipant GR = new GameParticipant();
                    GR.ShowDialog();
                }

                else if (message.Contains("GAMEGPQB")) //group
                {
                    ThreadHelper.Hide(this);

                    //this.Hide();//kaipuhn muna ithread
                    GameType = "QB";
                    //  GameRules GR = new GameRules();
                    // GR.Show();


                    GameGroup GR = new GameGroup();
                    GR.ShowDialog();
                }

                else if (message.Contains("GAMEGPPZ"))//group
                {
                    ThreadHelper.Hide(this);

                    //this.Hide();//kaipuhn muna ithread
                    GameType = "PZ";
                    //  GameRules GR = new GameRules();
                    // GR.Show();


                    GameGroup GR = new GameGroup();
                    GR.ShowDialog();
                }


                else if (message.Contains("GAMEFPQB"))
                {
                    ThreadHelper.Hide(this);

                    //this.Hide();//kaipuhn muna ithread
                    GameType = "QB";
                    //  GameRules GR = new GameRules();
                    // GR.Show();
                    GameFree GF = new GameFree();
                    GF.ShowDialog();
                }

                else if (message.Contains("GAMEFPPZ"))
                {
                    ThreadHelper.Hide(this);

                    //this.Hide();//kaipuhn muna ithread
                    GameType = "PZ";
                    //  GameRules GR = new GameRules();
                    // GR.Show();


                    GameFree GF = new GameFree();
                    GF.ShowDialog();
                }

                //client.Client.Shutdown(SocketShutdown.Both);
                //client.Client.Close();

                else
                {
                    ThreadHelper.lsbAddItem(this, lsbWait, message);
                    Receive();
                }
            }

            catch (Exception ex)
            {
                Dialogue.Show(" ' " + ex.Message.ToString() + "' ", "", "Ok", "Cancel");
            }
        }