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 : WasiNetwork

Remarks

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
WasiNetwork WasiHostNetwork

Constructors

NameDescription
WasiHostNetwork(WasiHostNetworkOptions)Initializes a new instance of the WasiHostNetwork class.

WasiHostNetwork(WasiHostNetworkOptions)

WasiHostNetwork.cs

Initializes a new instance of the WasiHostNetwork class.

public WasiHostNetwork(WasiHostNetworkOptions options)

Parameters

options WasiHostNetworkOptions
The rules of the network.

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)

WasiHostNetwork.cs

Creates a TCP socket.

public override 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)

WasiHostNetwork.cs

Creates a UDP socket.

public override 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)

WasiHostNetwork.cs

Returns 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

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, ...