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);
}
}
この例では、ソケット エラーが発生した場合、入力を取得してプログラムを終了するかどうかをユーザーに親切に尋ねています。そして、その入力を他の値と比較します。この場合、「はい」の文字列です。しかし、何らかの理由で「はい」と入力しても、if チェックがスキップされます。「サーバーとの接続が失われました。終了しますか?」というメッセージが出力されます。また。奇妙なことに、もう一度「はい」と入力すると機能します。cin.ignore(); を使用して修正しようとしました。これらすべてのものがありますが、解決策はありません。