while (true)
{
int read = recvData(clientSocket, buf, sizeof(buf));
if(read == SOCKET_ERROR)
{
cout<<"Connection with the server is lost. Do you want to exit?" << endl;
string input;
getline(cin,input);
if(input == "yes")
cout<<"test";
}
if(read == SHOW )
{
char *p = strtok(buf, " ");
while (p)
{
cout<<p<<endl;
p = strtok(NULL, " ");
}
}
else if(read == SEND )
{
UDPinfo* info = new UDPinfo;
char *p = strtok(buf, " ");
info->_IP = p;
p = strtok(NULL, " ");
info->_Port= p;
info->_filePath = filePath;
info->_UPDsock = UDPSocket;
//Starting UDP send thread.
_beginthread(UDPsendThread, 0, (void*)info);
}
}
in this example, if I get a socket error I'm kindly asking the user if he wants to exit the program by getting an input. And then comparing that input by some other value in this case its a "yes" string. But for some reason even if I type "yes" it skips the if check. and prints the "Connection with the server is lost. Do you want to exit?" again. The strange thing is, if I type "yes" again it works. I tried to fix it by using cin.ignore(); and all those stuff, but no solution.