Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
EndConnect Method

TcpClient.EndConnect Method

Asynchronously accepts an incoming connection attempt.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)

public void EndConnect(
	IAsyncResult asyncResult


Type: System.IAsyncResult
An IAsyncResult object returned by a call to BeginConnect.


The asyncResult parameter is null.


The asyncResult parameter was not returned by a call to a BeginConnect method.


The EndConnect method was previously called for the asynchronous connection.


An error occurred when attempting to access the Socket. See the Remarks section for more information.


The underlying Socket has been closed.

This method blocks until the operation is complete. To perform this operation synchronously, use a Connect method.


If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. After you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in the MSDN library at http://msdn.microsoft.com/library for a detailed description of the error.

The following code example ends the asynchronous connection attempt.

public static ManualResetEvent connectDone = 
    new ManualResetEvent(false);

public static void ConnectCallback(IAsyncResult ar)
    TcpClient t = (TcpClient)ar.AsyncState;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft