EndConnect Method
.NET Framework Class Library
TcpClient..::.EndConnect Method

Asynchronously accepts an incoming connection attempt.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Public Sub EndConnect ( _
    asyncResult As IAsyncResult _
)
Visual Basic (Usage)
Dim instance As TcpClient
Dim asyncResult As IAsyncResult

instance.EndConnect(asyncResult)
C#
public void EndConnect(
    IAsyncResult asyncResult
)
Visual C++
public:
void EndConnect(
    IAsyncResult^ asyncResult
)
JScript
public function EndConnect(
    asyncResult : IAsyncResult
)

Parameters

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

The asyncResult parameter is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentException

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

InvalidOperationException

The EndConnect method was previously called for the asynchronous connection.

SocketException

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

ObjectDisposedException

The underlying Socket has been closed.

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

NoteNote:

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.

C#
public static ManualResetEvent connectDone = 
    new ManualResetEvent(false);

public static void ConnectCallback(IAsyncResult ar)
{
    connectDone.Set();
    TcpClient t = (TcpClient)ar.AsyncState;
    t.EndConnect(ar);
}
Visual C++
static ManualResetEvent^ connectDone = gcnew ManualResetEvent( false );
static void ConnectCallback( IAsyncResult^ ar )
{
   connectDone->Set();
   TcpClient^ t = safe_cast<TcpClient^>(ar->AsyncState);
   t->EndConnect( ar );
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
Page view tracker