TcpListener.EndAcceptSocket Method

Asynchronously accepts an incoming connection attempt and creates a new Socket to handle remote host communication.

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

member EndAcceptSocket : 
        asyncResult:IAsyncResult -> Socket

Parameters

asyncResult
Type: System.IAsyncResult

An IAsyncResult returned by a call to the BeginAcceptSocket method.

Return Value

Type: System.Net.Sockets.Socket
A Socket.
The Socket used to send and receive data.

ExceptionCondition
ObjectDisposedException

The underlying Socket has been closed.

ArgumentNullException

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

ArgumentException

The asyncResult parameter was not created by a call to the BeginAcceptSocket method.

InvalidOperationException

The EndAcceptSocket method was previously called.

SocketException

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

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

NoteNote

You can call the RemoteEndPoint property of the returned Socket to identify the remote host's network address and port number.

NoteNote

If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code and 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.

NoteNote

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

The following code example demonstrates the use of the BeginAcceptSocket method to create and connect a socket. The callback delegate calls the EndAcceptSocket method to end the asynchronous request.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft