TcpListener.EndAcceptSocket(IAsyncResult) Method

Definition

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

C#
public System.Net.Sockets.Socket EndAcceptSocket(IAsyncResult asyncResult);

Parameters

asyncResult
IAsyncResult

An IAsyncResult returned by a call to the BeginAcceptSocket(AsyncCallback, Object) method.

Returns

A Socket.

The Socket used to send and receive data.

Exceptions

The underlying Socket has been closed.

The asyncResult parameter is null.

The asyncResult parameter was not created by a call to the BeginAcceptSocket(AsyncCallback, Object) method.

The EndAcceptSocket(IAsyncResult) method was previously called.

An error occurred while attempting to access the Socket.

Remarks

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

Note

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

Note

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 for a detailed description of the error.

Note

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

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1