public void SendPacket(byte[] packet) { Precondition.Check <InvalidOperationException>(Connected, "Socket is not connected"); Precondition.Check <InvalidOperationException>(Encrypted, "Handshake has not been received yet"); Precondition.Check <ArgumentException>(packet.Length >= 2, @"Packet length must be greater than 2"); lock (sendLock) { byte[] final = new byte[packet.Length + PACKET_HEADER_SIZE]; switch (SessionType) { case SessionType.CLIENT: clientCipher.GetHeaderToServer(packet.Length, final); break; case SessionType.SERVER: clientCipher.GetHeaderToClient(packet.Length, final); break; } clientCipher.Transform(packet); Buffer.BlockCopy(packet, 0, final, PACKET_HEADER_SIZE, packet.Length); SendRawPacket(final); } }
public void SendPacket(PacketWriter packet) { if (!m_connected) { throw new InvalidOperationException("Socket is not connected"); } if (!m_encrypted) { throw new InvalidOperationException("Handshake has not been received yet"); } byte[] data = packet.ToArray(); if (data.Length < 2) { throw new ArgumentOutOfRangeException("Packet length must be greater than 2", "packet"); } const int HeaderSize = 4; lock (m_sendLock) { byte[] final = new byte[data.Length + HeaderSize]; switch (m_sessionType) { case SessionType.Client: m_clientCipher.GetHeaderToServer(data.Length, final); break; case SessionType.Server: m_clientCipher.GetHeaderToClient(data.Length, final); break; } m_clientCipher.Transform(data); Buffer.BlockCopy(data, 0, final, HeaderSize, data.Length); SendRawPacket(final); } }