Socket.BeginConnect Method (IPAddress, Int32, AsyncCallback, Object)
Begins an asynchronous request for a remote host connection. The host is specified by an IPAddress and a port number.
Assembly: System (in System.dll)
<HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading := True)> Public Function BeginConnect ( address As IPAddress, port As Integer, requestCallback As AsyncCallback, state As Object ) As IAsyncResult
The port number of the remote host.
An AsyncCallback delegate that references the method to invoke when the connect operation is complete.
A user-defined object that contains information about the connect operation. This object is passed to the requestCallback delegate when the operation is complete.
address is null.
An error occurred when attempting to access the socket. See the Remarks section for more information.
The Socket has been closed.
The Socket is not in the socket family.
The port number is not valid.
The length of address is zero.
The asynchronous EndConnect method. Typically, the method is invoked by the requestCallback delegate.operation must be completed by calling the
To cancel a pending call to the BeginConnect method, close the Socket. When the Close method is called while an asynchronous operation is in progress, the callback provided to the BeginConnect method is called. A subsequent call to the EndConnect method will throw an ObjectDisposedException to indicate that the operation has been cancelled.
For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously
If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
If this socket has previously been disconnected, then BeginConnect must be called on a thread that will not exit until the operation is complete. This is a limitation of the underlying provider. Also the EndPoint that is used must be different.
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.
The execution context (the security context, the impersonated user, and the calling context) is cached for the asynchronous Socket methods. After the first use of a particular context (a specific asynchronous Socket method, a specific Socket instance, and a specific callback), subsequent uses of that context will see a performance improvement.
Available since 2.0