WasiUdpSocket Class

A UDP socket of a WasiNetwork.

public abstract class WasiUdpSocket : IDisposable

Remarks

The options have default implementations that keep the values, without effect on the socket.

Implements

Constructors

NameDescription
WasiUdpSocket()

WasiUdpSocket()

WasiNetwork.cs
protected WasiUdpSocket()

No documentation is available.

Properties

NameDescription
HopLimitGets or sets the time to live of the packets (IP_TTL, IPV6_UNICAST_HOPS).
LocalEndPointGets the local address of the socket, or null when it is not bound.
ReceiveBufferSizeGets or sets the size of the receive buffer (SO_RCVBUF).
SendBufferSizeGets or sets the size of the send buffer (SO_SNDBUF).

Gets or sets the time to live of the packets (IP_TTL, IPV6_UNICAST_HOPS).

public virtual int HopLimit { get; set; }

Property value

int

LocalEndPoint

Gets the local address of the socket, or null when it is not bound.

public abstract IPEndPoint? LocalEndPoint { get; }

Property value

IPEndPoint?

ReceiveBufferSize

WasiNetwork.cs

Gets or sets the size of the receive buffer (SO_RCVBUF).

public virtual int ReceiveBufferSize { get; set; }

Property value

int

SendBufferSize

WasiNetwork.cs

Gets or sets the size of the send buffer (SO_SNDBUF).

public virtual int SendBufferSize { get; set; }

Property value

int

Methods

NameDescription
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

localEndPoint IPEndPoint
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

remoteEndPoint IPEndPoint?
The remote address, or null to receive and send the datagrams of any address.

Exceptions

SocketException
The socket cannot be connected.

Dispose overloads

Closes the socket.

public void Dispose()

Dispose(bool)

Closes the socket.

protected abstract void Dispose(bool disposing)
Parameters
disposing bool
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

buffer Memory<byte>
The buffer of the data, of 64 KiB.
cancellationToken CancellationToken
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

datagram ReadOnlyMemory<byte>
The data of the datagram.
remoteEndPoint IPEndPoint
The destination.
cancellationToken CancellationToken
The token that is cancelled when the component cancels the call.

Returns

ValueTask

Exceptions

SocketException
The datagram cannot be sent.