WasiNetwork Class

The network of a WASI component (wasi:sockets, see WasiOptions.Network): the TCP and UDP sockets and the name lookups. WasiHostNetwork uses the network of the machine, with the rules of a WasiHostNetworkOptions; WasiInMemoryNetwork is a network inside the process.

public abstract class WasiNetwork

Remarks

WASI checks the states of the sockets and the arguments of the operations before calling the sockets (a socket that is already bound, an address of the wrong family, a connection to the port 0, ...): the sockets only perform the operations. The methods throw a SocketException to report an error: its SocketException.SocketErrorCode is converted to the error code of WASI.

Constructors

NameDescription
WasiNetwork()

WasiNetwork()

protected WasiNetwork()

No documentation is available.

Methods

NameDescription
CreateTcpSocket(AddressFamily)Creates a TCP socket.
CreateUdpSocket(AddressFamily)Creates a UDP socket.
ResolveAddressesAsync(string, CancellationToken)Returns the IP addresses of a host name, in the order of preference.

CreateTcpSocket(AddressFamily)

Creates a TCP socket.

public abstract WasiTcpSocket CreateTcpSocket(AddressFamily addressFamily)

Parameters

addressFamily AddressFamily
The address family: AddressFamily.InterNetwork or AddressFamily.InterNetworkV6 (only IPv6, not the IPv4-mapped addresses).

Returns

WasiTcpSocket

Exceptions

SocketException
The socket cannot be created.

CreateUdpSocket(AddressFamily)

Creates a UDP socket.

public abstract WasiUdpSocket CreateUdpSocket(AddressFamily addressFamily)

Parameters

addressFamily AddressFamily
The address family: AddressFamily.InterNetwork or AddressFamily.InterNetworkV6 (only IPv6, not the IPv4-mapped addresses).

Returns

WasiUdpSocket

Exceptions

SocketException
The socket cannot be created.

ResolveAddressesAsync(string, CancellationToken)

Returns the IP addresses of a host name, in the order of preference.

public abstract ValueTask<IReadOnlyList<IPAddress>> ResolveAddressesAsync(string name, CancellationToken cancellationToken)

Parameters

name string
The host name: WASI returns the IP addresses itself, without calling this method.
cancellationToken CancellationToken
The token that is cancelled when the component cancels the lookup.

Returns

ValueTask<IReadOnlyList<IPAddress>>

Exceptions

SocketException
The name cannot be resolved: SocketError.HostNotFound, SocketError.TryAgain, SocketError.AccessDenied, ...