Ejemplo n.º 1
0
        public async Task SendAsync(TCPClient client, Packet packet)
        {
            if (packet == null)
            {
                throw new NullReferenceException("packet is null");
            }
            if (client == null)
            {
                throw new NullReferenceException("client is null");
            }

            byte[]       data   = packet.Data;
            ClientOpcode opcode = packet.Opcode;

            byte[] buffer = new byte[data.Length + 4];

            Array.Copy(BitConverter.GetBytes((ushort)data.Length), 0, buffer, 0, 2);
            Array.Copy(BitConverter.GetBytes((ushort)opcode), 0, buffer, 2, 2);
            Array.Copy(data, 0, buffer, 4, data.Length);
            await client.SendAsync(buffer, buffer.Length);
        }