System.Net.Sockets.TcpClient.BeginConnect Method

Begins an asynchronous request for a remote host connection. The remote host is specified by an System.Net.IPAddress array and a port number (int).

Syntax

public IAsyncResult BeginConnect (System.Net.IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)

Parameters

addresses
At least one System.Net.IPAddress that designates the remote hosts.
port
The port number of the remote hosts.
requestCallback
An AsyncCallback delegate that references the method to invoke when the operation is complete.
state
A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete.

Returns

An IAsyncResult object that references the asynchronous connection.

Remarks

The asynchronous TcpClient.BeginConnect(System.Net.IPAddress, int, AsyncCallback, object) operation must be completed by calling the TcpClient.EndConnect(IAsyncResult) method. Typically, the method is invoked by the asyncCallback delegate.

This method does not block until the operation completes. To block until the operation completes, use one of the erload:System.Net.Sockets.TcpClient.Connect method overloads.

For detailed information about using the asynchronous programming model, see Asynchronous Programming Overview.

This method is typically used immediately after a call to the System.Net.Dns.BeginGetHostAddresses(string, AsyncCallback, object) method, which can return multiple IP addresses for a single host.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0