Beispiel #1
0
        public async Task Send <T>(T packet) where T : Packet
        {
            var packetBuffer = new byte[BufferSize];

            var packetBytes = _packetConverter.ToBytes(packet);

            if (packetBytes.Length > BufferSize)
            {
                throw new Exception($"Serialized packet is larger than buffer size of '{BufferSize}' bytes.");
            }

            packetBytes.CopyTo(packetBuffer, 0);

            //await _socket.SendAsync(buffer: new ArraySegment<byte>(array: packetBuffer, offset: 0, count: packetBuffer.Length), socketFlags: SocketFlags.None);
            await _socket.SendAsync(buffer : new ArraySegment <byte>(array: packetBytes, offset: 0, count: packetBytes.Length), socketFlags : SocketFlags.None);

            //await _socket.SendAsync(buffer: new ArraySegment<byte>(array: serializedPacketBuffer, offset: 0, count: serializedPacketBuffer.Length), socketFlags: SocketFlags.None);
        }