Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

How to keep client socket connection open with winsock?

$
0
0

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!





Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>