Given the original socket descriptor obtained from the socket() call, the close() call closes the socket and terminates the connection if it is still open. Some server applications close immediately after receiving client data, while others wait for additional connections. To compile on Windows, you must call the Winsock closesocket() instead of close().
#ifdef _WIN32 return closesocket(sockfd); #else return close(sockfd); #endif
The shutdown() function is like close(), but shuts down the connection.