我开发了一个 UDP 客户端服务器应用程序。现在我想检查客户端是否发送了一个字符串“EXIT”,服务器接收到这个字符串,将它与“EXIT”字符串进行比较,然后程序退出。但就我而言,服务器无法将接收到的字符串与“EXIT”字符串进行比较。以下是我正在编码的内容:
客户:
char exitBuffer[]="EXIT";
if (sendto(socketIdentifier,exitBuffer,strlen(exitBuffer) , 0 , (struct sockaddr *) &connectedSocket, sizeof(connectedSocket)) == SOCKET_ERROR)
{
exit(EXIT_FAILURE);
}
服务器:
if ((recv_len = recvfrom(socketIdentifier, receiveBuffer, sizeof(receiveBuffer), 0, (struct sockaddr *) &clientSocket, &clientSocketLength)) == SOCKET_ERROR)
{
MessageBox(NULL,
exit(EXIT_FAILURE);
}
// Now comparing the contents of receive Buffer
if (receiveBuffer == "EXIT")
{
exit(0);
}