Today we will discuss some important sockets functions which are almost used in any windows application which uses the sockets. These references are from the WinSock Version 2. So be sure to try them using the Version 2 or later.
Windows Sockets Reference - WinSock2
Function accept
Description: The accept function accepts an incoming request for connection attempt on a socket.
SOCKET accept(
SOCKET s,
struct sockaddr* addr,
int* addrlen
);
Parameters:
s: This identifies a socket that is in a listening state with the listen function. The connection is actually made with the socket that is returned by accept.
addr: Optional pointer to a buffer that receives the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family that was established when the socket from the SOCKADDR structure was created.
addrlen: Its an parameter of type pointer to an integer that contains the length of addr.
If everything goes well then it returns the Socket, and if there is an error then INVALID_SOCKET value is returned. To get the specific error code you can call WSAGetLastError function to get the last error occured in sockets operation. More...