The accept() function retrieves the first connection on the queue of pending connections on a listening socket. If there are no connections on the queue, the function blocks the calling process until a connection is present.
Note This function is part of the Winsock 1.1 API. For new development, use Winsock 2.0 or later. For more information, see Winsock Overview.
Syntax
SOCKET accept(
[in] SOCKET ListenSocket,
[out] PSOCKADDR Addr,
[in,out] int FAR* AddrLen
);
Parameters
| Parameter | Type | Description |
|---|---|---|
ListenSocket |
SOCKET |
A descriptor identifying the socket that is listening for connections. This socket must be in a listening state (see listen). |
Addr |
PSOCKADDR |
An optional pointer to a buffer that will receive the fully qualified domain name and port number for the client endpoint, as the name is known on the local host. For more information, see the SOCKADDR Structure. |
AddrLen |
int FAR* |
An optional pointer to a buffer on input that specifies the size of the buffer pointed to by Addr. On output, this parameter is updated to reflect the actual size of the buffer used for storing the client's address information. |
Return Value
If no error occurs, accept() returns a descriptor for a newly created socket that is connected to the client specified by Addr. This returned socket is a stream-based socket and is ready for sending and receiving data.
If an I/O error occurs, accept() returns INVALID_SOCKET. If the return value is INVALID_SOCKET, function WSAGetLastError can be called to obtain a specific error code.
Possible error codes:
WSAEINTR: A blocking call was interrupted by a call toWSACancelBlockingCall.WSAEINVAL: The socket or protocol is not in a valid state for this operation.WSAEMFILE: No more descriptors are available.WSAENOTSOCK: The descriptor is not a socket.WSAEOPNOTSUPP: The operation is not supported on the socket.WSAEWOULDBLOCK: The socket is nonblocking and no connections are present to be accepted.WSAECONNRESET: An established connection was aborted by the software on the other end of the socket.
Requirements
| Attribute | Value |
|---|---|
| Minimum supported client | Windows XP [desktop apps only] |
| Minimum supported server | Windows Server 2003 [desktop apps only] |
| Header | winsock2.h |
| Library | ws2_32.lib |
| DLL | ws2_32.dll |