Class UdpChannelTransmitter
Represents a UDP socket for sessions' datagrams: it hands each one it receives to its handler, and sends the sealed ones it is given.
public sealed class UdpChannelTransmitter : IDisposable
- Inheritance
-
UdpChannelTransmitter
- Implements
- Inherited Members
Remarks
A server's listener serves every session; a client's socket serves its own. A datagram shorter than a header never reaches the handler, and a socket that fails beyond use disposes the transmitter.
Constructors
UdpChannelTransmitter(UdpClient, IUdpDatagramHandler)
Initializes a new instance of the UdpChannelTransmitter class, which reads at once.
public UdpChannelTransmitter(UdpClient udpClient, IUdpDatagramHandler handler)
Parameters
udpClientUdpClientThe bound UDP client, which the transmitter owns.
handlerIUdpDatagramHandlerThe handler that takes each datagram received.
Exceptions
- InvalidOperationException
The UDP client's socket is not bound.
Properties
BufferSize
Gets or sets the socket's send and receive buffer sizes. A size above zero is set; any other gives back the system's default where a size was set before.
public TransferBufferSize? BufferSize { get; set; }
Property Value
Connected
Gets a value indicating whether the transmitter is in use: it is not disposed.
public bool Connected { get; }
Property Value
LocalEndPoint
Gets the socket's local endpoint.
public IPEndPoint LocalEndPoint { get; }
Property Value
Methods
Dispose()
Closes the socket, which ends the reading; a socket that fails to close is logged.
public void Dispose()
SendAsync(ReadOnlyMemory<byte>, IPEndPoint)
Sends a sealed datagram.
public Task SendAsync(ReadOnlyMemory<byte> datagram, IPEndPoint remoteEndPoint)
Parameters
datagramReadOnlyMemory<byte>The datagram.
remoteEndPointIPEndPointThe endpoint it goes to.
Returns
- Task
A task that completes once the socket has sent the datagram.
Remarks
Sessions send at once: each seals in a buffer of its own, and the socket takes concurrent sends. A failure is thrown. While the transmitter is in use, an ordinary one is logged, the first of each report period as a warning with its error and the others at the debug level; a socket in a state beyond use is logged as an error and disposes the transmitter.
Exceptions
- Exception
The socket sent less than the whole datagram.