WasiUdpSocket Class
A UDP socket of a WasiNetwork.
public abstract class WasiUdpSocket : IDisposableRemarks
The options have default implementations that keep the values, without effect on the socket.
- Implements
Constructors
| Name | Description |
|---|---|
| WasiUdpSocket() |
WasiUdpSocket()
WasiNetwork.csprotected WasiUdpSocket()No documentation is available.
Properties
| Name | Description |
|---|---|
| HopLimit | Gets or sets the time to live of the packets (IP_TTL, IPV6_UNICAST_HOPS). |
| LocalEndPoint | Gets the local address of the socket, or null when it is not bound. |
| ReceiveBufferSize | Gets or sets the size of the receive buffer (SO_RCVBUF). |
| SendBufferSize | Gets or sets the size of the send buffer (SO_SNDBUF). |
HopLimit
WasiNetwork.csLocalEndPoint
Gets the local address of the socket, or null when it is not bound.
public abstract IPEndPoint? LocalEndPoint { get; }Property value
ReceiveBufferSize
WasiNetwork.csSendBufferSize
WasiNetwork.csMethods
| Name | Description |
|---|---|
| Bind(IPEndPoint) | Binds the socket to a local address. The port 0 is a free port. |
| Connect(IPEndPoint?) | Limits the datagrams to a remote address (or removes the limit), after binding the socket to a free port when it is not bound. |
| Dispose() | Closes the socket. |
| Dispose(bool) | Closes the socket. |
| ReceiveFromAsync(Memory<byte>, CancellationToken) | Receives a datagram of a bound socket. |
| SendToAsync(ReadOnlyMemory<byte>, IPEndPoint, CancellationToken) | Sends a datagram, after binding the socket to a free port when it is not bound. |
Bind(IPEndPoint)
Binds the socket to a local address. The port 0 is a free port.
public abstract void Bind(IPEndPoint localEndPoint)Parameters
localEndPointIPEndPoint- An address of the family of the socket, or the unspecified address.
Exceptions
SocketException- The address is not available or is in use.
Connect(IPEndPoint?)
Limits the datagrams to a remote address (or removes the limit), after binding the socket to a free port when it is not bound.
public abstract void Connect(IPEndPoint? remoteEndPoint)Parameters
remoteEndPointIPEndPoint?- The remote address, or null to receive and send the datagrams of any address.
Exceptions
SocketException- The socket cannot be connected.
Dispose overloads
Dispose()
WasiNetwork.csCloses the socket.
public void Dispose()Dispose(bool)
Closes the socket.
Parameters
disposingbool- Whether the method is called by
WasiUdpSocket.Dispose.
ReceiveFromAsync(Memory<byte>, CancellationToken)
Receives a datagram of a bound socket.
public abstract ValueTask<(int Length, IPEndPoint RemoteEndPoint)> ReceiveFromAsync(Memory<byte> buffer, CancellationToken cancellationToken)Parameters
bufferMemory<byte>- The buffer of the data, of 64 KiB.
cancellationTokenCancellationToken- The token that is cancelled when the component cancels the call.
Returns
ValueTask<(int Length, IPEndPoint RemoteEndPoint)> The length of the datagram and its source.
Exceptions
SocketException- The datagram cannot be received.
SendToAsync(ReadOnlyMemory<byte>, IPEndPoint, CancellationToken)
Sends a datagram, after binding the socket to a free port when it is not bound.
public abstract ValueTask SendToAsync(ReadOnlyMemory<byte> datagram, IPEndPoint remoteEndPoint, CancellationToken cancellationToken)Parameters
datagramReadOnlyMemory<byte>- The data of the datagram.
remoteEndPointIPEndPoint- The destination.
cancellationTokenCancellationToken- The token that is cancelled when the component cancels the call.
Returns
Exceptions
SocketException- The datagram cannot be sent.