Пример #1
0
        private void Reject(TcpClient client, int clientId)
        {
            var stream = client.GetStream();

            var dataType = new DataToSend
            {
                ClientState = ClientState.Rejected,
                GameData    = _gameData
            };

            // Serializing data to bytes
            byte[] data = dataType.Serialize();

            // Sending data
            stream.Write(data, 0, data.Length);

            Log($"Data sent to id: {clientId}.");

            // Closing the connection
            stream.Close();
            client.Close();
        }
Пример #2
0
        private void Accept(TcpClient client, int clientId)
        {
            var stream = client.GetStream();

            // Adding new player to game data
            var player = new PlayerData("Michau", clientId);

            _gameData.AddPlayer(player);

            // Creating data to send
            var dataType = new DataToSend
            {
                GameData    = _gameData,
                ClientId    = clientId,
                ClientState = ClientState.Accepted
            };

            for (int i = 0; i < 1000; i++)
            {
                // Changing data
                player.PositionX = i;
                player.PositionY = 1000 - i;
                // Serializing data to bytes
                var data = dataType.Serialize();

                // Sending data
                stream.Write(data, 0, data.Length);

                Log($"Data sent to id: {clientId}.");

                Thread.Sleep(1000);
            }

            // Closing the connection
            stream.Close();
            client.Close();
        }