Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Net.​Sockets.​SocketTaskExtensions
Assembly: System.Net.Sockets
Inheritance: object → SocketTaskExtensions
This class contains extension methods to the <see cref="T:System.Net.Sockets.Socket" /> class.
Methods
public static
Threading.​Tasks.​Task<​Socket>
AcceptAsync​(Socket socket)
Performs an asynchronous operation on to accept an incoming connection attempt on the socket.
Returns An asynchronous task that completes with a <see cref="T:System.Net.Sockets.Socket" /> to handle communication with the remote host.
socket
The socket that is listening for connections.
public static
Threading.​Tasks.​Task<​Socket>
AcceptAsync​(Socket socket,
Socket? acceptSocket)
Performs an asynchronous operation on to accept an incoming connection attempt on the socket.
Returns An asynchronous task that completes with a <see cref="T:System.Net.Sockets.Socket" /> to handle communication with the remote host.
socket
The socket that is listening for incoming connections.
acceptSocket
The accepted <see cref="T:System.Net.Sockets.Socket" /> object. This value may be <see langword="null" /> .
public static
Threading.​Tasks.​Task
ConnectAsync​(Socket socket,
EndPoint remoteEP)
Establishes a connection to a remote host.
Returns An asynchronous Task.
socket
The socket that is used for establishing a connection.
remoteEP
An EndPoint that represents the remote device.
ConnectAsync​(Socket socket,
EndPoint remoteEP,
Threading.​CancellationToken cancellationToken)
Establishes a connection to a remote host.
Returns A task that represents the asynchronous connection operation.
socket
The socket that is used for establishing a connection.
remoteEP
An EndPoint that represents the remote device.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
public static
Threading.​Tasks.​Task
ConnectAsync​(Socket socket,
IPAddress address,
int port)
Establishes a connection to a remote host. The host is specified by an IP address and a port number.
Returns A task that represents an asynchronous connection operation.
socket
The socket to perform the connect operation on.
address
The IP address of the remote host.
port
The port number of the remote host.
ConnectAsync​(Socket socket,
IPAddress address,
int port,
Threading.​CancellationToken cancellationToken)
Establishes a connection to a remote host, which is specified by an IP address and a port number.
Returns A task that represents the asynchronous connection operation.
socket
The socket to perform the connect operation on.
address
The IP address of the remote host.
port
The port number of the remote host.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
public static
Threading.​Tasks.​Task
ConnectAsync​(Socket socket,
IPAddress[] addresses,
int port)
Establishes a connection to a remote host. The host is specified by an array of IP addresses and a port number.
Returns A task that represents the asynchronous connect operation.
socket
The socket that the connect operation is performed on.
addresses
The IP addresses of the remote host.
port
The port number of the remote host.
ConnectAsync​(Socket socket,
IPAddress[] addresses,
int port,
Threading.​CancellationToken cancellationToken)
Establishes a connection to a remote host, which is specified by an array of IP addresses and a port number.
Returns A task that represents the asynchronous connection operation.
socket
The socket that the connect operation is performed on.
addresses
The IP addresses of the remote host.
port
The port number of the remote host.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
public static
Threading.​Tasks.​Task
ConnectAsync​(Socket socket,
string host,
int port)
Establishes a connection to a remote host. The host is specified by a host name and a port number.
Returns An asynchronous task.
socket
The socket to perform the connect operation on.
host
The name of the remote host.
port
The port number of the remote host.
ConnectAsync​(Socket socket,
string host,
int port,
Threading.​CancellationToken cancellationToken)
Establishes a connection to a remote host, which is specified by a host name and a port number.
Returns A task that represents an asynchronous connection operation.
socket
The socket to perform the connect operation on.
host
The name of the remote host.
port
The port number of the remote host.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
public static
Threading.​Tasks.​Task<​int>
ReceiveAsync​(Socket socket,
ArraySegment<​byte> buffer,
SocketFlags socketFlags)
Receives data from a connected socket.
Returns A task that represents the asynchronous receive operation. The value of the <paramref name="TResult" /> parameter contains the number of bytes received.
socket
The socket to perform the receive operation on.
buffer
An array that is the storage location for the received data.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
public static
Threading.​Tasks.​Task<​int>
ReceiveAsync​(Socket socket,
Collections.​Generic.​IList<​ArraySegment<​byte>> buffers,
SocketFlags socketFlags)
Receives data from a connected socket.
Returns A task that represents the asynchronous receive operation. The value of the <paramref name="TResult" /> parameter contains the number of bytes received.
socket
The socket to perform the receive operation on.
buffers
An array that is the storage location for the received data.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
public static
Threading.​Tasks.​ValueTask<​int>
ReceiveAsync​(Socket socket,
Memory<​byte> buffer,
SocketFlags socketFlags,
Threading.​CancellationToken cancellationToken = null)
Receives data from a connected socket.
Returns A task that completes with the number of bytes received, or 0 if the end of the stream has been reached.
socket
The socket to perform the receive operation on.
buffer
A region of memory that is the storage location for the received data.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
public static
Threading.​Tasks.​Task<​SocketReceiveFromResult>
ReceiveFromAsync​(Socket socket,
ArraySegment<​byte> buffer,
SocketFlags socketFlags,
EndPoint remoteEndPoint)
Receives data from a specified network device.
Returns An asynchronous Task that completes with a SocketReceiveFromResult struct.
socket
The socket to perform the ReceiveFrom operation on.
buffer
An array of type Byte that is the storage location for the received data.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
remoteEndPoint
An EndPoint that represents the source of the data.
public static
Threading.​Tasks.​Task<​SocketReceiveMessageFromResult>
ReceiveMessageFromAsync​(Socket socket,
ArraySegment<​byte> buffer,
SocketFlags socketFlags,
EndPoint remoteEndPoint)
Receives the specified number of bytes of data into the specified location of the data buffer, using the specified <see cref="T:System.Net.Sockets.SocketFlags" /> , and stores the endpoint and packet information.
Returns An asynchronous Task that completes with a <see cref="T:System.Net.Sockets.SocketReceiveMessageFromResult" /> struct.
socket
The socket to perform the operation on.
buffer
An array that is the storage location for received data.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
remoteEndPoint
An <see cref="T:System.Net.EndPoint" /> , that represents the remote server.
public static
Threading.​Tasks.​Task<​int>
SendAsync​(Socket socket,
ArraySegment<​byte> buffer,
SocketFlags socketFlags)
Sends data to a connected socket.
Returns An asynchronous task that completes with number of bytes sent to the socket if the operation was successful. Otherwise, the task will complete with an invalid socket error.
socket
The socket to perform the operation on.
buffer
An array of type Byte that contains the data to send.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
public static
Threading.​Tasks.​Task<​int>
SendAsync​(Socket socket,
Collections.​Generic.​IList<​ArraySegment<​byte>> buffers,
SocketFlags socketFlags)
Sends data to a connected socket.
Returns An asynchronous task that completes with number of bytes sent to the socket if the operation was successful. Otherwise, the task will complete with an invalid socket error.
socket
The socket to perform the operation on.
buffers
An array that contains the data to send.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
public static
Threading.​Tasks.​ValueTask<​int>
SendAsync​(Socket socket,
ReadOnlyMemory<​byte> buffer,
SocketFlags socketFlags,
Threading.​CancellationToken cancellationToken = null)
Sends data to a connected socket.
Returns A task that completes with number of bytes sent to the socket if the operation was successful. Otherwise, the task will complete with an invalid socket error.
socket
The socket to perform the operation on.
buffer
A region of memory that contains the data to send.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
public static
Threading.​Tasks.​Task<​int>
SendToAsync​(Socket socket,
ArraySegment<​byte> buffer,
SocketFlags socketFlags,
EndPoint remoteEP)
Sends data asynchronously to a specific remote host.
Returns An asynchronous task that completes with number of bytes sent if the operation was successful. Otherwise, the task will complete with an invalid socket error.
socket
The socket to perform the operation on.
buffer
An array that contains the data to send.
socketFlags
A bitwise combination of the <see cref="T:System.Net.Sockets.SocketFlags" /> values.
remoteEP
An <see cref="T:System.Net.EndPoint" /> that represents the remote device.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object