void HandleTCPClient(int clntSocket)
{
int recvMsgSize;
char echoBuffer[32];
char test[32];
char reply[32];
memset(&echoBuffer,0,sizeof(echoBuffer));
memset(&test,0,sizeof(test));
memset(&reply,0,sizeof(reply));
if((recvMsgSize = recv(clntSocket, echoBuffer, 32, 0)) <0)
{
DieWithError("recv() failed.");
}
while (recvMsgSize > 0)
{
if(send(clntSocket, echoBuffer, recvMsgSize, 0) != recvMsgSize)
{
DieWithError("send() failed.");
}
if((recvMsgSize = recv(clntSocket, echoBuffer,
32, 0)) <0)
{
DieWithError("recv() failed.");
}
if(test == echoBuffer)
printf("HELLO IT WORKED\n");
}
close(clntSocket);
}
This is the server handler for the TCP/IP client I am using. Sadly, it does not work. This is really frustrating me as I have tried everything imaginable to get this code to work to no avail so I am resorting to posting for the first time in these forums. I NEED HELP!
I've tried cleaning the string with memset;
Ive tried adding "\n" to the end of the string
I've tried adding "\0" to the end of the string
Ive tried adding "\n\0" to the end of the string
It's just not working. Something is seriously wrong here. What I want to do is send a text command to the server via the client and process that command by echoing the working directory. The command is pwd.
But, no matter what I do - I can echo pwd back to the client (which is nc) but I cannot get the server to recognise any string sent to it. Please help!