+ Reply to Thread
Results 1 to 2 of 2

Thread: How to close a socket safely?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    37

    How to close a socket safely?

    How to close a socket safely?

    Currently I am doing following:

    Code:
    closesocket(hSocket) ;
    is it safe?

  2. #2
    One approach for blocking socket is:

    Code:
    void MyCloseSocket(SOCKET &hSocket)
    {
    	shutdown(hSocket, SD_BOTH) ;
    	closesocket(hSocket) ;
    	hSocket = INVALID_SOCKET ;
    }
    More robust approach can be:
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts