SocketTaskExtensions.ReceiveAsync 方法

定义

重载

ReceiveAsync(Socket, ArraySegment<Byte>, SocketFlags)

接收连接的套接字发出的数据。Receives data from a connected socket.

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

接收连接的套接字发出的数据。Receives data from a connected socket.

ReceiveAsync(Socket, Memory<Byte>, SocketFlags, CancellationToken)

接收连接的套接字发出的数据。Receives data from a connected socket.

ReceiveAsync(Socket, ArraySegment<Byte>, SocketFlags)

接收连接的套接字发出的数据。Receives data from a connected socket.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Threading::Tasks::Task<int> ^ ReceiveAsync(System::Net::Sockets::Socket ^ socket, ArraySegment<System::Byte> buffer, System::Net::Sockets::SocketFlags socketFlags);
public static System.Threading.Tasks.Task<int> ReceiveAsync (this System.Net.Sockets.Socket socket, ArraySegment<byte> buffer, System.Net.Sockets.SocketFlags socketFlags);
static member ReceiveAsync : System.Net.Sockets.Socket * ArraySegment<byte> * System.Net.Sockets.SocketFlags -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ReceiveAsync (socket As Socket, buffer As ArraySegment(Of Byte), socketFlags As SocketFlags) As Task(Of Integer)

参数

socket
Socket

要对其执行 Receive 操作的套接字。The socket to perform the receive operation on.

buffer
ArraySegment<Byte>

一个数组,它是接收的数据的存储位置。An array that is the storage location for the received data.

socketFlags
SocketFlags

SocketFlags 值的按位组合。A bitwise combination of the SocketFlags values.

返回

Task<Int32>

表示异步接收操作的任务。A task that represents the asynchronous receive operation. TResult 参数的值包含接收的字节数。The value of the TResult parameter contains the number of bytes received.

适用于

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

接收连接的套接字发出的数据。Receives data from a connected socket.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Threading::Tasks::Task<int> ^ ReceiveAsync(System::Net::Sockets::Socket ^ socket, System::Collections::Generic::IList<ArraySegment<System::Byte>> ^ buffers, System::Net::Sockets::SocketFlags socketFlags);
public static System.Threading.Tasks.Task<int> ReceiveAsync (this System.Net.Sockets.Socket socket, System.Collections.Generic.IList<ArraySegment<byte>> buffers, System.Net.Sockets.SocketFlags socketFlags);
static member ReceiveAsync : System.Net.Sockets.Socket * System.Collections.Generic.IList<ArraySegment<byte>> * System.Net.Sockets.SocketFlags -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ReceiveAsync (socket As Socket, buffers As IList(Of ArraySegment(Of Byte)), socketFlags As SocketFlags) As Task(Of Integer)

参数

socket
Socket

要对其执行 Receive 操作的套接字。The socket to perform the receive operation on.

buffers
IList<ArraySegment<Byte>>

一个数组,它是接收的数据的存储位置。An array that is the storage location for the received data.

socketFlags
SocketFlags

SocketFlags 值的按位组合。A bitwise combination of the SocketFlags values.

返回

Task<Int32>

表示异步接收操作的任务。A task that represents the asynchronous receive operation. TResult 参数的值包含接收的字节数。The value of the TResult parameter contains the number of bytes received.

适用于

ReceiveAsync(Socket, Memory<Byte>, SocketFlags, CancellationToken)

接收连接的套接字发出的数据。Receives data from a connected socket.

public static System.Threading.Tasks.ValueTask<int> ReceiveAsync (this System.Net.Sockets.Socket socket, Memory<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, System.Threading.CancellationToken cancellationToken = default);
static member ReceiveAsync : System.Net.Sockets.Socket * Memory<byte> * System.Net.Sockets.SocketFlags * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
<Extension()>
Public Function ReceiveAsync (socket As Socket, buffer As Memory(Of Byte), socketFlags As SocketFlags, Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Integer)

参数

socket
Socket

要对其执行 Receive 操作的套接字。The socket to perform the receive operation on.

buffer
Memory<Byte>

内存中的一个区域,它是所接收的数据的存储位置。A region of memory that is the storage location for the received data.

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

返回

ValueTask<Int32>

完成并显示所接收的字节数的任务;如果已到达流的末尾,则字节数为 0。A task that completes with the number of bytes received, or 0 if the end of the stream has been reached.

适用于