I have developed a UDP Client Server Application. Now I want to check if the client sends a string "EXIT", the Server receives this string, compares it with "EXIT" string and the program exits. But in my case, the Server is not able to compare the received string with "EXIT" string. below is what I am coding:
Client:
char exitBuffer[]="EXIT";
if (sendto(socketIdentifier,exitBuffer,strlen(exitBuffer) , 0 , (struct sockaddr *) &connectedSocket, sizeof(connectedSocket)) == SOCKET_ERROR)
{
exit(EXIT_FAILURE);
}
SERVER:
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);
}
I tried memcmp and it did it :) Now the comparison done on the Server side is as follows:
if(memcmp(receiveBuffer,"EXIT",5) == 0)
{
//receiveBuffer is eqaul to "EXIT".
}