title: C++ Windows Sockets - Close socket at program exit
body: <p>I'm making a simple console client/server application with the WinSock2 api, but I need to make sure that the socket of the client closes properly when exiting the application. I have already tried to use a <code>SetConsoleCtrlHandler</code> but that makes a thread where the main loop keeps running for 10 seconds.</p>
  
  <p>Is there a way to close the socket when the user pressed the close button?</p>