close() is a * nix function. It will work with any file descriptor, and sockets in * nix is ββan example of a file descriptor, so it will close sockets correctly.
closesocket() is a Windows-specific function that works specifically with sockets. Sockets on Windows do not use nix-type file descriptors, socket() instead returns a handle to the kernel object, so it should be closed using closesocket() .
I find it rather shameful that BSD sockets do not include a specific copy of the socket function that can be used anywhere - but this is life.
Last, but not least, donβt confuse the shutdown 'socket with closing the socket. shutdown() stops transmission on the socket, but the socket remains on the system and all resources associated with it remain. You still need to close the socket after it is closed.
SergeyA
source share