I'm trying to understand this standard socket example:
// Receive data until the server 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);
it seems that this loop server only to get one response from the server, is that correct?
How do I keep this socket "alive", so it keeps listening to what the server might decide to send later?
Does iResult == 0 mean that the server has closed the connection (as it says) and I need to open another one, or do I wrap this code in another loop with some Sleep() function in it and keep calling recv()?
Thank you!