コード例 #1
0
        static void Main(string[] args)
        {
            bool isRunning = true;

            IPAddress iPAddress = IPAddress.Parse("127.0.0.1");
            int       port      = 5000;

            TcpListener tcpListener = new TcpListener(iPAddress, port);

            tcpListener.Start();

            Socket       socket;
            ThreadClient threadClient;

            while (isRunning == true)
            {
                socket = tcpListener.AcceptSocket();
                clientNumber++;
                threadClient = new ThreadClient(clientNumber, socket);

                threadClient.OnMessage += ThreadClient_OnMessage;

                threadClient.OnKill += ThreadClient_OnKill;

                threadClient.Sleep();
                threadClients.Add(threadClient);
                Console.WriteLine($"Adicionando a lista {threadClients.Count}");

                threadClient.Start();

                if (clientNumber == 2)
                {
                    StartGame();
                }
                else
                {
                    threadClient.Write(new Message()
                    {
                        Type = 1,
                        Text = "Entrando na partida..."
                    });
                }
                Console.WriteLine("Qauntidade de cliente :" + clientNumber);
            }
        }
コード例 #2
0
 private void TatamentoCliente(SocketServer server, Socket clientSocket)
 {
     this.thread = new ThreadClient(clientSocket, server);
     thread.Start();
 }