Пример #1
0
        private void buttonNextQuestion_Click(object sender, EventArgs e)
        {
            SendToAllClients("StartGame");

            this.Hide();
            GameFacilitator GF = new GameFacilitator();

            GF.ShowDialog();
        }
        private void BeginReceiveCallback(IAsyncResult ar)
        {
            try
            {
                //Get the client socket
                TcpClient clientSocket = (TcpClient)ar.AsyncState;
                //Get the received bytes from the client
                int received = clientSocket.Client.EndReceive(ar);
                // Get the string value of the received buffer
                string message = System.Text.Encoding.ASCII.GetString(buffer, 0, received);

                //Check if a disconenct flag was received
                if (message.Contains("SCORE"))
                {
                    //ThreadHelper.lsbAddItem(this, lsbJoined, message);

                    GameFacilitator GF = (GameFacilitator)Application.OpenForms["GameFacilitator"];
                    GF.updateScore(message.ToString());
                    // Send("You ("+message+ ") are now connected! Please Wait",clientSocket);


                    //Begin receiving data from the client socket
                    Receive(clientSocket);
                }


                else if (message.Contains("IMAGE"))
                {
                    GameFacilitator GF = (GameFacilitator)Application.OpenForms["GameFacilitator"];
                    GF.PUZZLEScore(message.ToString());

                    Receive(clientSocket);
                }



                else if (message.Contains("DISCONNECT"))
                {
                    ThreadHelper.lsbAddItem(this, lsbJoined, clientSocket.Client.RemoteEndPoint.ToString() + " has disconnected.");
                    //send a disconnect flag to the client to complete disconnection
                    Send("DISCONNECT", clientSocket);
                    //remove the client socket from the client list
                    clientSockets.Remove(clientSocket.Client.RemoteEndPoint.ToString());
                }



                else
                {
                    ThreadHelper.lsbAddItem(this, lsbJoined, message);


                    // Send("You ("+message+ ") are now connected! Please Wait",clientSocket);


                    //Begin receiving data from the client socket
                    Receive(clientSocket);
                }
            }
            catch (Exception ex)
            {
                // ThreadHelper.lsbAddItem(this, lsbJoined, ex.ToString());
                ThreadHelper.lsbAddItem(this, lsbJoined, "Error Detected!,Please Close this Lobby and Reconnect.");
            }
        }