NetworkClient
Abstract base class for UDP network clients.
Inherits: BaseLogReceiver
Implements: INetworkClient, ILogReceiver, ILogSource, IDisposable, IPacketProcessor
Constructors
protected NetworkClient(IUdpDialect dialect, string name, MulticastSourceAddress address, Func<TNetworkClient, IMemoryOwner<byte>, List<Message>, bool> processMessage, IPacketReceiverFactory receiverFactory)
networkClient = NetworkClient(dialect, name, address, processMessage, receiverFactory)
Initializes a new instance of the NetworkClient class.
- dialect
- The UDP dialect.
- name
- The client name.
- address
- The multicast source address.
- processMessage
- Function to process received messages.
- receiverFactory
- IPacketReceiverFactory
Properties
public IUdpDialect Dialect { get; }
value = networkClient.Dialect
Gets the UDP dialect associated with this client.
public PacketQueueFullModes FullMode { get; set; }
value = networkClient.FullMode
networkClient.FullMode = value
Behavior when the packet queue is full.
public bool IsEnabled { get; }
value = networkClient.IsEnabled
Gets a value indicating whether the client is enabled.
public int MaxIncomingQueueSize { get; }
value = networkClient.MaxIncomingQueueSize
Gets or sets the maximum incoming queue size.
public int MaxUdpDatagramSize { get; }
value = networkClient.MaxUdpDatagramSize
Gets or sets the maximum UDP datagram size.
Methods
public IMemoryOwner<byte> AllocatePacket(int size)
result = networkClient.AllocatePacket(size)
To allocate a packet of the specified size.
- size
- The size of the packet to allocate.
Returns: The packet.
public void Connect()
networkClient.Connect()
Connects the client using the specified serializer.
protected override void DisposeManaged()
networkClient.DisposeManaged()
Disposes the managed resources. Override this method to add custom clean up of managed resources.
public void DisposePacket(IMemoryOwner<byte> packet, string reason)
networkClient.DisposePacket(packet, reason)
Disposes the packet with the specified reason.
- packet
- The packet.
- reason
- The specified reason.
public void ErrorHandler(Exception e, int numErrors, bool isFatal)
networkClient.ErrorHandler(e, numErrors, isFatal)
Handles errors that occur during packet processing.
- e
- The exception encountered.
- numErrors
- The error count.
- isFatal
- Indicates whether the error is fatal.
public ValueTask<bool> ProcessNewPacket(IMemoryOwner<byte> packet, int length, CancellationToken cancellationToken)
result = networkClient.ProcessNewPacket(packet, length, cancellationToken)
Processes a new packet.
- packet
- The packet data.
- length
- The packet length.
- cancellationToken
- Cancellation token.
Returns: True to continue processing, false to stop.