MSDN Documentation

accept Function (Winsock)

The accept function retrieves the next pending connection on a socket.

C++
SOCKET accept(
    SOCKET  s,
    struct sockaddr *addr,
    LPINT  addrlen
);
                

Parameters

Parameter Description
s A descriptor that identifies the listening socket. This socket must be in a listening state.
addr A pointer to a buffer that receives the address of the connecting entity, as known to the communications layer. The structure of the address is determined by the address family established when the listening socket was created.
addrlen A pointer to an integer that specifies the size, in bytes, of the buffer pointed to by the addr parameter. When accept returns, this parameter is set to the actual length of the address returned.

Return Value

If no error occurs, accept returns a descriptor for a newly created socket that is connected to the remote host. This returned socket contains the same properties as the listening socket. If an error occurs, the return value is INVALID_SOCKET. To get extended error information, call GetLastError.

Remarks

The accept function establishes a connection with the first socket in the queue of pending connections. If there are no pending connections on the socket, a connection-oriented socket is created, and the function blocks until a connection is made.

If the calling process or thread has only one stack, it is unable to receive messages or perform other socket operations while blocked in accept.

If the socket is a non-blocking socket, accept returns when no connections are present to be accepted.

The addr parameter is a value-result argument. The application must provide a buffer large enough to hold the incoming connection's address. The parameter is then filled with the socket address of the connecting entity.

The length of the buffer pointed to by addr can be modified by the system. The application should always check the value of this parameter after the call returns.

A Windows Sockets implementation can choose to accept incoming connections that are not explicitly bound to any particular port on the local host. This behavior is determined by the SO_GROUP_PRIORITY socket option.

Requirements

Information Value
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header Winsock2.h (include Winsock2.h)
Library Ws2_32.lib
DLL Ws2_32.dll