I am making a small program that has a server and client communicating on the same machine, which is does. But I can't get the server to wait to receive a message back from the client. Why does the loop not wait at the int iRecvA = recv(acceptSocket, machId, STRLEN, 0);
line like it does the first time around? I proceeds to the last else
.
while (!done)
{
int iRecvA = recv(acceptSocket, machId, STRLEN, 0);
int iRecvB = recv(acceptSocket, serialNum, STRLEN, 0);
if (iRecvA && iRecvB > 0)
{
//stuff
}
else if (iRecvA && iRecvB == 0)
{
cout << "Connection closed\n";
cleanup(acceptSocket);
return 0;
}
else
{
cerr << "ERROR: Failed to receive message\n";
cleanup(acceptSocket);
return 1;
}
strcpy_s(sendMessage, "Activation was successful!\n\n\n");
int iSend = send(acceptSocket, sendMessage, strlen(sendMessage), 0);
if (iSend == SOCKET_ERROR)
{
cerr << "ERROR: Failed to send message\n";
cleanup(acceptSocket);
return 1;
}
}