CASyncSocket && receive
-
Is there any way to timeout receive function? I mean,if no data is send to me and I'm receiving. How I could stop this receiving nicely? For example in 30 seconds? My code: do { cout << "Socket Receiving" << endl; nRead = tmpSocket->Receive(ReceiveStr, RECEIVE_BUFFER_SIZE); strBuilder.addString(ReceiveStr, nRead); } while (nRead == RECEIVE_BUFFER_SIZE);
-
Is there any way to timeout receive function? I mean,if no data is send to me and I'm receiving. How I could stop this receiving nicely? For example in 30 seconds? My code: do { cout << "Socket Receiving" << endl; nRead = tmpSocket->Receive(ReceiveStr, RECEIVE_BUFFER_SIZE); strBuilder.addString(ReceiveStr, nRead); } while (nRead == RECEIVE_BUFFER_SIZE);
-
Use setsockopt function. For example: int timeout = 10; setsockopt(tmpSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));