SocketTaskExtensions.ConnectAsync 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.
ConnectAsync(Socket, IPAddress[], Int32, CancellationToken) |
Establishes a connection to a remote host, which is specified by an array of IP addresses and a port number. |
ConnectAsync(Socket, IPAddress, Int32, CancellationToken) |
Establishes a connection to a remote host, which is specified by an IP address and a port number. |
ConnectAsync(Socket, String, Int32) |
Establishes a connection to a remote host. The host is specified by a host name and a port number. |
ConnectAsync(Socket, String, Int32, CancellationToken) |
Establishes a connection to a remote host, which is specified by a host name and a port number. |
ConnectAsync(Socket, IPAddress, Int32) |
Establishes a connection to a remote host. The host is specified by an IP address and a port number. |
ConnectAsync(Socket, EndPoint, CancellationToken) |
Establishes a connection to a remote host. |
ConnectAsync(Socket, EndPoint) |
Establishes a connection to a remote host. |
ConnectAsync(Socket, IPAddress[], Int32) |
Establishes a connection to a remote host. The host is specified by an array of IP addresses and a port number. |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
Establishes a connection to a remote host, which is specified by an array of IP addresses and a port number.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::ValueTask ConnectAsync(System::Net::Sockets::Socket ^ socket, cli::array <System::Net::IPAddress ^> ^ addresses, int port, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.ValueTask ConnectAsync (this System.Net.Sockets.Socket socket, System.Net.IPAddress[] addresses, int port, System.Threading.CancellationToken cancellationToken);
static member ConnectAsync : System.Net.Sockets.Socket * System.Net.IPAddress[] * int * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
<Extension()>
Public Function ConnectAsync (socket As Socket, addresses As IPAddress(), port As Integer, cancellationToken As CancellationToken) As ValueTask
Parameters
- socket
- Socket
The socket that the connect operation is performed on.
- addresses
- IPAddress[]
The IP addresses of the remote host.
- port
- Int32
The port number of the remote host.
- cancellationToken
- CancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
Returns
A task that represents the asynchronous connection operation.
Exceptions
The addresses
parameter cannot be null.
The addresses
parameter cannot be empty array.
The Socket is listening.
An error occurred when attempting to access the socket.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
The cancellation token was canceled. This exception is stored into the returned task.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | 5, 6, 7, 8, 9 |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
Establishes a connection to a remote host, which is specified by an IP address and a port number.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::ValueTask ConnectAsync(System::Net::Sockets::Socket ^ socket, System::Net::IPAddress ^ address, int port, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.ValueTask ConnectAsync (this System.Net.Sockets.Socket socket, System.Net.IPAddress address, int port, System.Threading.CancellationToken cancellationToken);
static member ConnectAsync : System.Net.Sockets.Socket * System.Net.IPAddress * int * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
<Extension()>
Public Function ConnectAsync (socket As Socket, address As IPAddress, port As Integer, cancellationToken As CancellationToken) As ValueTask
Parameters
- socket
- Socket
The socket to perform the connect operation on.
- address
- IPAddress
The IP address of the remote host.
- port
- Int32
The port number of the remote host.
- cancellationToken
- CancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
Returns
A task that represents the asynchronous connection operation.
Exceptions
The address
parameter cannot be null.
The Socket is listening.
An error occurred when attempting to access the socket.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
The cancellation token was canceled. This exception is stored into the returned task.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | 5, 6, 7, 8, 9 |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
Establishes a connection to a remote host. The host is specified by a host name and a port number.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task ^ ConnectAsync(System::Net::Sockets::Socket ^ socket, System::String ^ host, int port);
public static System.Threading.Tasks.Task ConnectAsync (this System.Net.Sockets.Socket socket, string host, int port);
static member ConnectAsync : System.Net.Sockets.Socket * string * int -> System.Threading.Tasks.Task
<Extension()>
Public Function ConnectAsync (socket As Socket, host As String, port As Integer) As Task
Parameters
- socket
- Socket
The socket to perform the connect operation on.
- host
- String
The name of the remote host.
- port
- Int32
The port number of the remote host.
Returns
An asynchronous task.
Exceptions
The host
parameter cannot be null.
The Socket is listening.
An error occurred when attempting to access the socket.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
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
Establishes a connection to a remote host, which is specified by a host name and a port number.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::ValueTask ConnectAsync(System::Net::Sockets::Socket ^ socket, System::String ^ host, int port, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.ValueTask ConnectAsync (this System.Net.Sockets.Socket socket, string host, int port, System.Threading.CancellationToken cancellationToken);
static member ConnectAsync : System.Net.Sockets.Socket * string * int * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
<Extension()>
Public Function ConnectAsync (socket As Socket, host As String, port As Integer, cancellationToken As CancellationToken) As ValueTask
Parameters
- socket
- Socket
The socket to perform the connect operation on.
- host
- String
The name of the remote host.
- port
- Int32
The port number of the remote host.
- cancellationToken
- CancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
Returns
A task that represents an asynchronous connection operation.
Exceptions
The host
parameter cannot be null.
The Socket is listening.
An error occurred when attempting to access the socket.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
The cancellation token was canceled. This exception is stored into the returned task.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | 5, 6, 7, 8, 9 |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
Establishes a connection to a remote host. The host is specified by an IP address and a port number.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task ^ ConnectAsync(System::Net::Sockets::Socket ^ socket, System::Net::IPAddress ^ address, int port);
public static System.Threading.Tasks.Task ConnectAsync (this System.Net.Sockets.Socket socket, System.Net.IPAddress address, int port);
static member ConnectAsync : System.Net.Sockets.Socket * System.Net.IPAddress * int -> System.Threading.Tasks.Task
<Extension()>
Public Function ConnectAsync (socket As Socket, address As IPAddress, port As Integer) As Task
Parameters
- socket
- Socket
The socket to perform the connect operation on.
- address
- IPAddress
The IP address of the remote host.
- port
- Int32
The port number of the remote host.
Returns
A task that represents an asynchronous connection operation.
Exceptions
The address
parameter cannot be null.
The Socket is listening.
An error occurred when attempting to access the socket.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
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
Establishes a connection to a remote host.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::ValueTask ConnectAsync(System::Net::Sockets::Socket ^ socket, System::Net::EndPoint ^ remoteEP, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.ValueTask ConnectAsync (this System.Net.Sockets.Socket socket, System.Net.EndPoint remoteEP, System.Threading.CancellationToken cancellationToken);
static member ConnectAsync : System.Net.Sockets.Socket * System.Net.EndPoint * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
<Extension()>
Public Function ConnectAsync (socket As Socket, remoteEP As EndPoint, cancellationToken As CancellationToken) As ValueTask
Parameters
- socket
- Socket
The socket that is used for establishing a connection.
- remoteEP
- EndPoint
An EndPoint that represents the remote device.
- cancellationToken
- CancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
Returns
A task that represents the asynchronous connection operation.
Exceptions
The remoteEP
parameter cannot be null.
The Socket is listening.
An error occurred when attempting to access the socket.
The local endpoint and the remoteEP
parameter are not the same address family.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
The cancellation token was canceled. This exception is stored into the returned task.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | 5, 6, 7, 8, 9 |
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
- Source:
- SocketTaskExtensions.cs
Establishes a connection to a remote host.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task ^ ConnectAsync(System::Net::Sockets::Socket ^ socket, System::Net::EndPoint ^ remoteEP);
public static System.Threading.Tasks.Task ConnectAsync (this System.Net.Sockets.Socket socket, System.Net.EndPoint remoteEP);
static member ConnectAsync : System.Net.Sockets.Socket * System.Net.EndPoint -> System.Threading.Tasks.Task
<Extension()>
Public Function ConnectAsync (socket As Socket, remoteEP As EndPoint) As Task
Parameters
- socket
- Socket
The socket that is used for establishing a connection.
- remoteEP
- EndPoint
An EndPoint that represents the remote device.
Returns
An asynchronous Task.
Exceptions
The remoteEP
parameter cannot be null.
The Socket is listening.
An error occurred when attempting to access the socket.
The local endpoint and the remoteEP
parameter are not the same address family.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
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
Establishes a connection to a remote host. The host is specified by an array of IP addresses and a port number.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task ^ ConnectAsync(System::Net::Sockets::Socket ^ socket, cli::array <System::Net::IPAddress ^> ^ addresses, int port);
public static System.Threading.Tasks.Task ConnectAsync (this System.Net.Sockets.Socket socket, System.Net.IPAddress[] addresses, int port);
static member ConnectAsync : System.Net.Sockets.Socket * System.Net.IPAddress[] * int -> System.Threading.Tasks.Task
<Extension()>
Public Function ConnectAsync (socket As Socket, addresses As IPAddress(), port As Integer) As Task
Parameters
- socket
- Socket
The socket that the connect operation is performed on.
- addresses
- IPAddress[]
The IP addresses of the remote host.
- port
- Int32
The port number of the remote host.
Returns
A task that represents the asynchronous connect operation.
Exceptions
The addresses
parameter cannot be null.
The addresses
parameter cannot be empty array.
The Socket is listening.
An error occurred when attempting to access the socket.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: