|
-
January 9th, 2010, 12:49 PM
#1
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...
-
January 9th, 2010, 04:06 PM
#2
Re: shutdown socket WSAGetLastError 10057
Victor Nijegorodov
-
January 11th, 2010, 09:45 AM
#3
Re: shutdown socket WSAGetLastError 10057
 Originally Posted by VictorN
what must i do with this???
-
January 11th, 2010, 11:02 AM
#4
Re: shutdown socket WSAGetLastError 10057
Error 10057 means WSAENOTCONN (Socket is not connected.)
So why are you trying to shutdown disconnected socket?
Victor Nijegorodov
-
January 12th, 2010, 09:58 AM
#5
Re: shutdown socket WSAGetLastError 10057
 Originally Posted by VictorN
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?
-
January 12th, 2010, 10:54 AM
#6
Re: shutdown socket WSAGetLastError 10057
 Originally Posted by auliac
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:
- Call WSAAsyncSelect to register for FD_CLOSE notification.
- Call shutdown with how=SD_SEND.
- When FD_CLOSE received, call recv until zero returned, or SOCKET_ERROR.
- 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
-
January 13th, 2010, 10:44 AM
#7
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..
-
January 13th, 2010, 11:19 AM
#8
Re: shutdown socket WSAGetLastError 10057
 Originally Posted by auliac
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
-
January 14th, 2010, 02:57 AM
#9
Re: shutdown socket WSAGetLastError 10057
okay,,, thanks for your help and suggestion....
-
January 22nd, 2010, 09:51 AM
#10
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 !
-
January 22nd, 2010, 10:00 AM
#11
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|