SocketTaskExtensions.ReceiveAsync Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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. |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
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)
Parameters
- socket
- Socket
The socket to perform the receive operation on.
- buffer
- ArraySegment<Byte>
An array that is the storage location for the received data.
- socketFlags
- SocketFlags
A bitwise combination of the SocketFlags values.
Returns
A task that represents the asynchronous receive operation. The value of the TResult
parameter contains the number of bytes received.
Exceptions
The Socket has been closed.
An error occurred when attempting to access the socket.
Applies to
.NET 9 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 |
.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 |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
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)
Parameters
- socket
- Socket
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
A bitwise combination of the SocketFlags values.
Returns
A task that represents the asynchronous receive operation. The value of the TResult
parameter contains the number of bytes received.
Exceptions
The buffers
parameter was null.
The Socket has been closed.
An error occurred when attempting to access the socket.
Applies to
.NET 9 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 |
.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 |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
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)
Parameters
- socket
- Socket
The socket to perform the receive operation on.
- 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 the number of bytes received, or 0 if the end of the stream has been reached.
Exceptions
The Socket has been closed.
An error occurred when attempting to access the socket.
The cancellation token was canceled. This exception is stored into the returned task.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Standard | 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: