Advertisement

Recv returning 0

Started by December 19, 2002 11:31 AM
5 comments, last by logout 22 years, 1 month ago
I recv() says that i am getting 0 bytes back into my program and WSAGetLastError() returns 0 what am i doing wrong ?
Don''t know. What does you code look like?
Advertisement
for sending :
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.
:wq!
Hm... is it the one that is trying to revc() or the one that is trying to send() ???
Advertisement
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?

This topic is closed to new replies.

Advertisement