Ejemplo n.º 1
0
        private void _sendGameState(IPEndPoint ipep)
        {
            var data         = BinaryHelper.SaveGameState(CurrentGameState, Level.GameLevel.CurrentLevelWidth, Level.GameLevel.CurrentLevelHeight);
            int numOfPackets = data.Length / _MAX_UDP_PACKET_SIZE;

            if (data.Length % _MAX_UDP_PACKET_SIZE != 0)
            {
                numOfPackets++;
            }

            _client.Send(BitConverter.GetBytes(data.Length), sizeof(int), ipep);

            int currentPacketSize;

            for (int i = 0; i < numOfPackets; i++)
            {
                if ((i + 1) * _MAX_UDP_PACKET_SIZE > data.Length)
                {
                    currentPacketSize = data.Length - i * _MAX_UDP_PACKET_SIZE;
                }
                else
                {
                    currentPacketSize = _MAX_UDP_PACKET_SIZE;
                }
                _client.Client.SendTo(data, i * _MAX_UDP_PACKET_SIZE, currentPacketSize, SocketFlags.None, ipep);
            }
        }