recv 收到数据,但是返回0,请问是什么问题?谢谢
[解决办法]
Return value
If no error occurs, recv returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data received. If the connection has been gracefully closed, the return value is zero.
Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
Error code
WSANOTINITIALISED
A successful WSAStartup call must occur before using this function.
WSAENETDOWN
The network subsystem has failed.
WSAEFAULT
The buf parameter is not completely contained in a valid part of the user address space.
WSAENOTCONN
The socket is not connected.
WSAEINTR
The (blocking) call was canceled through WSACancelBlockingCall.
WSAEINPROGRESS
A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAENETRESET
For a connection-oriented socket, this error indicates that the connection has been broken due to keep-alive activity that detected a failure while the operation was in progress. For a datagram socket, this error indicates that the time to live has expired.
WSAENOTSOCK
The descriptor is not a socket.
WSAEOPNOTSUPP
MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations.
WSAESHUTDOWN
The socket has been shut down; it is not possible to receive on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH.
WSAEWOULDBLOCK
The socket is marked as nonblocking and the receive operation would block.
WSAEMSGSIZE
The message was too large to fit into the specified buffer and was truncated.
WSAEINVAL
The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative.
WSAECONNABORTED
The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.
WSAETIMEDOUT
The connection has been dropped because of a network failure or because the peer system failed to respond.
WSAECONNRESET
The virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket as it is no longer usable. On a UDP-datagram socket, this error would indicate that a previous send operation resulted in an ICMP "Port Unreachable" message.
// Receive until the peer closes the connection
do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
printf("Bytes received: %d\n", iResult);
else if ( iResult == 0 )
printf("Connection closed\n");
else
printf("recv failed: %d\n", WSAGetLastError());
} while( iResult > 0 );
[解决办法]
求截图!
如:

[解决办法]
到该步是不是链接被关闭了啊?
[解决办法]
知道了!呵呵
看你调试就知道了,你肯定定义了2个ret。
不然ret = recv(m_MgmntSock, resultBuf, resultBufSize, 0);到}while(false);一步ret肯定也是红色的,你那里居然不是红色,只有resultBuf是红色.
后面看了下你最上面的代码,果然定义了2个ret....