CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2009
    Posts
    68

    shutdown socket WSAGetLastError 10057

    helo friend.....!!!

    i try to built an aplication. i got difficult how to break connection between client-server.

    Code:
    void CComputer::OnButtonStart() 
    {
    ...
    ...
    sServer = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
    ...
    ...
    }
    
    // my disconnect function
    void CComputer::OnButtonStop() 
    {
    ....
    ....
    // try to shutdown
    if (shutdown(CComputer::sServer,2)==SOCKET_ERROR)
    	{
    		info.Format("socket() failed: %d", WSAGetLastError());
                   AfxMessageBox(info);
                   return;
    	}
    ....
    .....
    }
    from that code i got error "socket() failed: 10057". as we know, that error message come from my shutdown().

    how can i repair it???

    thanks...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: shutdown socket WSAGetLastError 10057

    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2009
    Posts
    68

    Re: shutdown socket WSAGetLastError 10057

    Quote Originally Posted by VictorN View Post
    what must i do with this???

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: shutdown socket WSAGetLastError 10057

    Error 10057 means WSAENOTCONN (Socket is not connected.)
    So why are you trying to shutdown disconnected socket?
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2009
    Posts
    68

    Re: shutdown socket WSAGetLastError 10057

    Quote Originally Posted by VictorN View Post
    Error 10057 means WSAENOTCONN (Socket is not connected.)
    So why are you trying to shutdown disconnected socket?
    it still connected. i knew it from my client aplication. if sServer is a "disconnected socket" my client aplication will knowit.

    Code:
    shutdown(CComputer::sServer,2)
    if i call socket like above. is that right method?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: shutdown socket WSAGetLastError 10057

    Quote Originally Posted by auliac View Post
    Code:
    shutdown(CComputer::sServer,2)
    if i call socket like above. is that right method?
    I have no idea what '2' means.
    According to MSDN there may be either SD_RECEIVE or SD_SEND or SD_BOTH:
    shutdown
    The Windows Sockets shutdown function disables sends or receives on a socket.
    ...............
    Remarks

    The shutdown function is used on all types of sockets to disable reception, transmission, or both.

    If the how parameter is SD_RECEIVE, subsequent calls to the recv function on the socket will be disallowed. This has no effect on the lower protocol layers. For TCP sockets, if there is still data queued on the socket waiting to be received, or data arrives subsequently, the connection is reset, since the data cannot be delivered to the user. For UDP sockets, incoming datagrams are accepted and queued. In no case will an ICMP error packet be generated.

    If the how parameter is SD_SEND, subsequent calls to the send function are disallowed. For TCP sockets, a FIN will be sent after all data is sent and acknowledged by the receiver.

    Setting how to SD_BOTH disables both sends and receives as described above.

    The shutdown function does not close the socket. Any resources attached to the socket will not be freed until closesocket is invoked.

    To assure that all data is sent and received on a connected socket before it is closed, an application should use shutdown to close connection before calling closesocket. For example, to initiate a graceful disconnect:

    1. Call WSAAsyncSelect to register for FD_CLOSE notification.
    2. Call shutdown with how=SD_SEND.
    3. When FD_CLOSE received, call recv until zero returned, or SOCKET_ERROR.
    4. Call closesocket.
    Note The shutdown function does not block regardless of the SO_LINGER setting on the socket.

    An application should not rely on being able to reuse a socket after it has been shut down. In particular, a Windows Sockets provider is not required to support the use of connect on a socket that has been shut down.
    Victor Nijegorodov

  7. #7
    Join Date
    Aug 2009
    Posts
    68

    Re: shutdown socket WSAGetLastError 10057

    before i post my thread here, i tried like code below
    Code:
    shutdown(CComputer::sServer,SD_BOTH)
    and i got message "SD_BOTH undeclared identifier " from my compiler.

    thanks very much for you attention..

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: shutdown socket WSAGetLastError 10057

    Quote Originally Posted by auliac View Post
    before i post my thread here, i tried like code below
    Code:
    shutdown(CComputer::sServer,SD_BOTH)
    and i got message "SD_BOTH undeclared identifier " from my compiler.
    Reading MSDN saves you much time, BTW!
    FROM MSDN article "shutdown":
    Requirements
    Version: Requires Windows Sockets 1.1 or later.
    Header: Declared in Winsock2.h.
    Library: Use Ws2_32.lib.
    Victor Nijegorodov

  9. #9
    Join Date
    Aug 2009
    Posts
    68

    Re: shutdown socket WSAGetLastError 10057

    okay,,, thanks for your help and suggestion....

  10. #10
    Join Date
    Jul 2005
    Posts
    185

    Re: shutdown socket WSAGetLastError 10057

    And by the way, for the two of you, the "2" at the shutdown() is the actual value of SD_BOTH !

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: shutdown socket WSAGetLastError 10057

    Quote Originally Posted by mikoil View Post
    And by the way, for the two of you, the "2" at the shutdown() is the actual value of SD_BOTH !
    Wow! I am you know it now!
    However, I think 9 days is too much to look at the SD_BOTH definition in the Winsock2.h file! (see post#8)
    Victor Nijegorodov

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured