SocketTaskExtensions.SendAsync Method

Definition

Overloads

SendAsync(Socket, ReadOnlyMemory<Byte>, SocketFlags, CancellationToken)

Source:
SocketTaskExtensions.cs
Source:
SocketTaskExtensions.cs
Source:
SocketTaskExtensions.cs

Sends data to a connected socket.

C#
public static System.Threading.Tasks.ValueTask<int> SendAsync(this System.Net.Sockets.Socket socket, ReadOnlyMemory<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, System.Threading.CancellationToken cancellationToken = default);

Parameters

socket
Socket

The socket to perform the operation on.

buffer
ReadOnlyMemory<Byte>

A region of memory that contains the data to send.

socketFlags
SocketFlags

A bitwise combination of the SocketFlags values.

cancellationToken
CancellationToken

A cancellation token that can be used to signal the asynchronous operation should be canceled.

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.

Exceptions

An error occurred when attempting to access the socket.

The Socket has been closed.

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

SendAsync(Socket, ArraySegment<Byte>, SocketFlags)

Source:
SocketTaskExtensions.cs
Source:
SocketTaskExtensions.cs
Source:
SocketTaskExtensions.cs

Sends data to a connected socket.

C#
public static System.Threading.Tasks.Task<int> SendAsync(this System.Net.Sockets.Socket socket, ArraySegment<byte> buffer, System.Net.Sockets.SocketFlags socketFlags);

Parameters

socket
Socket

The socket to perform the operation on.

buffer
ArraySegment<Byte>

An array of type Byte that contains the data to send.

socketFlags
SocketFlags

A bitwise combination of the SocketFlags values.

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.

Exceptions

An error occurred when attempting to access the socket.

The Socket has been closed.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

SendAsync(Socket, IList<ArraySegment<Byte>>, SocketFlags)

Source:
SocketTaskExtensions.cs
Source:
SocketTaskExtensions.cs
Source:
SocketTaskExtensions.cs

Sends data to a connected socket.

C#
public static System.Threading.Tasks.Task<int> SendAsync(this System.Net.Sockets.Socket socket, System.Collections.Generic.IList<ArraySegment<byte>> buffers, System.Net.Sockets.SocketFlags socketFlags);

Parameters

socket
Socket

The socket to perform the operation on.

buffers
IList<ArraySegment<Byte>>

An array that contains the data to send.

socketFlags
SocketFlags

A bitwise combination of the SocketFlags values.

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.

Exceptions

buffers is null.

An error occurred when attempting to access the socket.

The Socket has been closed.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1