cleanup use of CloseSocket()

- call CloseSocket() before printing any text (ensure consistent
  usage in the code), exception is when using NetworkErrorString()
add CSocket (RAII class that provides access to a SOCKET)