/// <summary> /// Sends the specified payload over TCP. /// </summary> /// <param name="payloadWriter">The action which writes the payload to a buffer.</param> public void SendTcp(Action <BitBuffer> payloadWriter) { lock (this) { if (CurrentState == State.Disconnected) { return; } byte[] encrypted; using (_sendBuffer) { _sendBuffer.Write(_sendSequenceId); if (++_sendSequenceId == _sequenceIdBound) { _sendSequenceId = 0; } payloadWriter(_sendBuffer); encrypted = _crypto.Encrypt(_sendBuffer.Array, 0, _sendBuffer.Size); } using (_sendBuffer) { _sendBuffer.Write((ushort)encrypted.Length); _sendBuffer.Write(encrypted); _tcp.Send(_sendBuffer.Array, 0, _sendBuffer.Size); } } }
private void SendEncryptedLengthPrefixOnlyTcp(Socket recipient, byte[] encryptionKey, Action <BitBuffer> payloadWriter) { byte[] encrypted; using (_sendBuffer) { payloadWriter(_sendBuffer); encrypted = _crypto.Encrypt(encryptionKey, _sendBuffer.Array, 0, _sendBuffer.Size); } using (_sendBuffer) { _sendBuffer.Write((ushort)encrypted.Length); _sendBuffer.Write(encrypted); _tcp.Send(recipient, _sendBuffer.Array, 0, _sendBuffer.Size); } }