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 WasiNetworkRemarks
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
| Name | Description |
|---|---|
| WasiNetwork() |
WasiNetwork()
protected WasiNetwork()No documentation is available.
Methods
| Name | Description |
|---|---|
| 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
addressFamilyAddressFamily- The address family:
AddressFamily.InterNetworkorAddressFamily.InterNetworkV6(only IPv6, not the IPv4-mapped addresses).
Returns
Exceptions
SocketException- The socket cannot be created.
CreateUdpSocket(AddressFamily)
Creates a UDP socket.
public abstract WasiUdpSocket CreateUdpSocket(AddressFamily addressFamily)Parameters
addressFamilyAddressFamily- The address family:
AddressFamily.InterNetworkorAddressFamily.InterNetworkV6(only IPv6, not the IPv4-mapped addresses).
Returns
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
namestring- The host name: WASI returns the IP addresses itself, without calling this method.
cancellationTokenCancellationToken- 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, ...