I have a problem in my recv () loop for winsock. I try to end the loop when iResult == 0, however the loop only ends after the socket is closed. It seems to be hanging on the very last recv (), where iResult will be 0. So, any ideas on how to effectively complete the loop? My ultimate goal (whether iResult == 0 or not, maybe I'm doing it wrong) is to stop the loop when all the information sent has been read. Here is a loop.
do { iResult = recv(socket, recvbuf, BUFLEN-1, 0); if(iResult > 0){ // Null byte :) // Remove that garbage >:( recvbuf[iResult] = '\0'; printf("Recvbuf: %s\n\n\niResult: %d\n",recvbuf,iResult); continue; // working properly } else if(iResult == 0) // Connection closed properly break; else { printf("ERROR! %ld",WSAGetLastError()); break; } } while(iResult > 0);
As I said, I get all the data, I just can not exit the loop. The next step is to write data to the server, but it hangs here until the ping timeout. Socket SOCK_STREAM and BUFLEN are defined as 0x200
thanks
c ++ windows winapi winsock recv
Raaged
source share