Re: Receive no data

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"mmlab_js" <mmlabjs@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote...
I modify the code on line 117:
do {
??recvbytes = recv(sockfd, recvbuf, recvbuflen, 0);
??if (recvbytes == SOCKET_ERROR)
????ErrExit(sockfd, "recv() failed with error: %d.\n", WSAGetLastError());
} while(recvbytes == 0);
If "no data available at this time", I think that it SHOULD receive some
data. But it doesn't.

I see two mistakes here:

1. "while(recvbytes == 0);". This should be "while (recvbytes > 0)". It may just be a
typo in your post though instead of actual code.

2. If multiple recv() calls receive data, each subsequent calls will overwrite the data
in the recvbuf that was store there by previous calls.

In order to receive the response data into a buffer first and process it later, you
should use something like:

offset = 0;
do {
recvbytes = recv(sockfd, recvbuf+offset, recvbuflen-offset, 0);
if (recvbytes == SOCKET_ERROR)
ErrExit(sockfd, "recv() failed with error: %d.\n", WSAGetLastError());
offset += recvbytes;
} while(recvbytes > 0);

Regards,
-Roger
--
E-mail: rhunen@xxxxxxxxx
Home: http://www.xs4all.nl/~rhunen
ADSL: http://adsl.hunen.net


.