WasiHostNetwork Class
- Not supported on browser
A network that uses the sockets of the machine (Socket), with the rules of a WasiHostNetworkOptions.
[UnsupportedOSPlatform("browser")]
public sealed class WasiHostNetwork : WasiNetworkRemarks
The IPv6 sockets only use IPv6 (IPV6_V6ONLY). The TCP sockets reuse the addresses of the closed connections (SO_REUSEADDR, the default on Windows). The sockets are not supported on the browser.
Example
// The component can only use the loopback addresses (the services of this machine), and cannot look up names
var network = new WasiHostNetwork(new WasiHostNetworkOptions
{
AddressCheck = WasiHostNetworkOptions.AllowLoopback,
AllowNameLookup = false,
AllowUdp = false,
});
var wasi = new WasiComponentContext(new WasiOptions { Network = network });- Inheritance
WasiNetworkWasiHostNetwork
Constructors
| Name | Description |
|---|---|
| WasiHostNetwork(WasiHostNetworkOptions) | Initializes a new instance of the WasiHostNetwork class. |
WasiHostNetwork(WasiHostNetworkOptions)
WasiHostNetwork.csInitializes a new instance of the WasiHostNetwork class.
public WasiHostNetwork(WasiHostNetworkOptions options)Parameters
optionsWasiHostNetworkOptions- The rules of the network.
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)
WasiHostNetwork.csCreates a TCP socket.
public override 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)
WasiHostNetwork.csCreates a UDP socket.
public override 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)
WasiHostNetwork.csReturns the IP addresses of a host name, in the order of preference.
net10.0
public override ValueTask<IReadOnlyList<IPAddress>> ResolveAddressesAsync(string name, CancellationToken cancellationToken)net11.0
public override 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, ...