-1

我开发了一个 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);
}
4

1 回答 1

0

我尝试了 memcmp 并且它做到了:) 现在在服务器端进行的比较如下:

if(memcmp(receiveBuffer,"EXIT",5) == 0)
{
    //receiveBuffer is eqaul to "EXIT".
}
于 2013-03-18T07:45:32.083 回答