WasiTcpSocket Class
A TCP socket of a WasiNetwork.
public abstract class WasiTcpSocket : IDisposableRemarks
The options have default implementations that keep the values, without effect on the socket.
- Implements
Constructors
| Name | Description |
|---|---|
| WasiTcpSocket() |
WasiTcpSocket()
WasiNetwork.csprotected WasiTcpSocket()No documentation is available.
Properties
| Name | Description |
|---|---|
| HopLimit | Gets or sets the time to live of the packets (IP_TTL, IPV6_UNICAST_HOPS). |
| KeepAlive | Gets or sets whether the socket sends keep-alive packets (SO_KEEPALIVE). |
| KeepAliveCount | Gets or sets the number of keep-alive packets without answer before the connection is closed (TCP_KEEPCNT). |
| KeepAliveIdleTime | Gets or sets the time without data before the first keep-alive packet (TCP_KEEPIDLE). |
| KeepAliveInterval | Gets or sets the time between the keep-alive packets (TCP_KEEPINTVL). |
| ListenBacklog | Gets or sets the size of the queue of the pending connections. |
| LocalEndPoint | Gets the local address of the socket, or null when it is not bound. |
| ReceiveBufferSize | Gets or sets the size of the receive buffer (SO_RCVBUF). |
| RemoteEndPoint | Gets the remote address of a connected socket, or null. |
| SendBufferSize | Gets or sets the size of the send buffer (SO_SNDBUF). |
HopLimit
WasiNetwork.csKeepAlive
WasiNetwork.csKeepAliveCount
WasiNetwork.csKeepAliveIdleTime
WasiNetwork.csKeepAliveInterval
WasiNetwork.csListenBacklog
WasiNetwork.csLocalEndPoint
Gets the local address of the socket, or null when it is not bound.
public abstract IPEndPoint? LocalEndPoint { get; }Property value
ReceiveBufferSize
WasiNetwork.csRemoteEndPoint
Gets the remote address of a connected socket, or null.
public abstract IPEndPoint? RemoteEndPoint { get; }Property value
SendBufferSize
WasiNetwork.csMethods
| Name | Description |
|---|---|
| AcceptAsync(CancellationToken) | Accepts a connection of a listening socket. |
| Bind(IPEndPoint) | Binds the socket to a local address. The port 0 is a free port. |
| ConnectAsync(IPEndPoint, CancellationToken) | Connects the socket to a remote address, after binding it to a free port when it is not bound. |
| Dispose() | Closes the socket. |
| Dispose(bool) | Closes the socket. |
| Listen(int) | Starts listening for connections. The socket is bound. |
| ReceiveAsync(Memory<byte>, CancellationToken) | Receives data from the peer of a connected socket. |
| SendAsync(ReadOnlyMemory<byte>, CancellationToken) | Sends data to the peer of a connected socket. |
| ShutdownSend() | Shuts down the sending side of the connection: the peer receives the end of the data. |
AcceptAsync(CancellationToken)
Accepts a connection of a listening socket.
public abstract ValueTask<WasiTcpSocket> AcceptAsync(CancellationToken cancellationToken)Parameters
cancellationTokenCancellationToken- The token that is cancelled when the component drops the stream of the connections.
Returns
ValueTask<WasiTcpSocket> The connected socket.
Exceptions
SocketException- The connection failed.
Bind(IPEndPoint)
Binds the socket to a local address. The port 0 is a free port.
public abstract void Bind(IPEndPoint localEndPoint)Parameters
localEndPointIPEndPoint- A unicast address of the family of the socket, or the unspecified address.
Exceptions
SocketException- The address is not available or is in use.
ConnectAsync(IPEndPoint, CancellationToken)
Connects the socket to a remote address, after binding it to a free port when it is not bound.
public abstract ValueTask ConnectAsync(IPEndPoint remoteEndPoint, CancellationToken cancellationToken)Parameters
remoteEndPointIPEndPoint- A unicast address of the family of the socket, with a port.
cancellationTokenCancellationToken- The token that is cancelled when the component cancels the connection.
Returns
Exceptions
SocketException- The connection failed.
Dispose overloads
Dispose()
WasiNetwork.csCloses the socket.
public void Dispose()Dispose(bool)
Closes the socket.
Parameters
disposingbool- Whether the method is called by
WasiTcpSocket.Dispose.
Listen(int)
Starts listening for connections. The socket is bound.
Parameters
backlogint- The size of the queue of the pending connections.
Exceptions
SocketException- The socket cannot listen.
ReceiveAsync(Memory<byte>, CancellationToken)
Receives data from the peer of a connected socket.
public abstract ValueTask<int> ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken)Parameters
bufferMemory<byte>- The buffer that receives the data.
cancellationTokenCancellationToken- The token that is cancelled when the component drops the stream of the data.
Returns
ValueTask<int> The number of bytes received, or 0 when the peer shut down its side of the connection.
Exceptions
SocketException- The connection is reset.
SendAsync(ReadOnlyMemory<byte>, CancellationToken)
Sends data to the peer of a connected socket.
public abstract ValueTask SendAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)Parameters
bufferReadOnlyMemory<byte>- The data.
cancellationTokenCancellationToken- The token that is cancelled when the component cancels the copy.
Returns
Exceptions
SocketException- The connection is broken or reset.
ShutdownSend()
Shuts down the sending side of the connection: the peer receives the end of the data.
public abstract void ShutdownSend()