Share via


Socket.Accept Method

Creates a socket for a newly created connection.

Note

Before calling the Accept method, you must first call the Listen method to listen for and queue incoming connection requests.

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

Syntax

public Socket Accept ()

Return Value

A new Socket object that specifies the socket for the newly created connection.

Remarks

The Accept method synchronously extracts the first pending connection request from the connection request queue of the listening socket, and then it creates and returns a new Socket object. You cannot use this returned Socket object to accept any additional connections from the connection queue. However, you can use the RemoteEndPoint property of the returned Socket object to identify the remote host's network address and port number.

In blocking mode, the Accept method blocks until an incoming connection attempt is queued. After a connection is accepted, the original Socket object continues queuing incoming connection requests until you close the connection.

If you call the Accept method using a nonblocking Socket object and no connection requests are queued, Accept throws a SocketException exception. If you receive this type of exception, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows® Sockets 2.0 API error code documentation in the MSDN® Library for a detailed description of the error.

Version Information

Available in .NET Micro Framework version 2.0, 2.5

See Also

Reference

Socket Class
Socket Members
System.Net.Sockets Namespace