Class AbstractHapChannel
- Namespace
- AppleTvControlLibrary.Mrp.AirPlay.Channels
- Assembly
- AppleTvControlLibrary.Mrp.dll
Base class for a TCP connection using HAP encryption and length-based segmenting, as used by the AirPlay 2 event and data-stream channels.
public abstract class AbstractHapChannel : IDisposable
- Inheritance
-
AbstractHapChannel
- Implements
- Derived
- Inherited Members
Remarks
This is the transport-level piece; message-specific encode/decode and dispatch belong to subclasses (see DataStreamChannel).
Constructors
AbstractHapChannel(byte[], byte[])
Initializes a new instance of the AbstractHapChannel class.
protected AbstractHapChannel(byte[] outputKey, byte[] inputKey)
Parameters
outputKeybyte[]The key used to encrypt outgoing data.
inputKeybyte[]The key used to decrypt incoming data.
Properties
Buffer
Gets the accumulated, decrypted-but-not-yet-consumed receive buffer.
protected List<byte> Buffer { get; }
Property Value
Remarks
Subclasses drain this in HandleReceived() as complete messages become available.
Methods
ConnectAsync(string, int, CancellationToken)
Connect to the remote endpoint and start the background read loop.
public Task ConnectAsync(string address, int port, CancellationToken cancellationToken = default)
Parameters
addressstringThe remote address.
portintThe remote port.
cancellationTokenCancellationTokenA token used to cancel the connection attempt.
Returns
Dispose()
Closes the channel.
public void Dispose()
HandleReceived()
Handle data that has been decrypted and appended to Buffer.
protected abstract void HandleReceived()
OnConnectionLost(Exception?)
Called when the underlying connection is dropped, cleanly or otherwise.
protected virtual void OnConnectionLost(Exception? exception)
Parameters
Send(byte[])
Send raw (pre-encryption) data to the remote device.
protected void Send(byte[] data)
Parameters
databyte[]The plaintext to encrypt and send.