Recv returning 0
I recv() says that i am getting 0 bytes back into my program
and
WSAGetLastError() returns 0
what am i doing wrong ?
for sending :
recv :
i am using TCP/IP
return send(sock, szBuff, 256, 0);
recv :
return recv(sock, szBuff, 256, 0);
i am using TCP/IP
Well, that''s not much to go on, but from what you wrote, it''s safe to say that your recv succeeded with no errors and returned 0 bytes. Have you set up your socket to block until bytes have been received?
uhh.. from the docs:
>Return Values:
>
>If no error occurs, recv returns the number of bytes 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.
>Return Values:
>
>If no error occurs, recv returns the number of bytes 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.
:wq!
Hm... is it the one that is trying to revc() or the one that is trying to send() ???
December 21, 2002 10:51 PM
recv returns 0 on graceful disconnection.
If you use blocking sockets it will block until bytes have been received and then return the number of bytes received (which must be greater than 0 obviously).
If you use non-blocking and there is no data, it will return SOCKET_ERROR and the last error should be WSAEWOULDBLOCK (if i remember the spelling correctly).
Most likely your connection is being closed. Is it possible the other end of the connection is closing the connection before sending any data?
If you use blocking sockets it will block until bytes have been received and then return the number of bytes received (which must be greater than 0 obviously).
If you use non-blocking and there is no data, it will return SOCKET_ERROR and the last error should be WSAEWOULDBLOCK (if i remember the spelling correctly).
Most likely your connection is being closed. Is it possible the other end of the connection is closing the connection before sending any data?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement