Hello,
I'm trying to make client program which connects to server, and comunicates with it for unlimited time. SOCK_STREAM (TCP).
Is there a way to change the way of getting server messages? Now it's just infinite loop. (I think thats not good, and requires a lot of CPU cycles)
while (1) {
memset(buff,0,255);
recv( sock,buff,255,0);
if (strstr(buff,"PING") != 0)
send(sock,"PONG :\r\n",6,0);
if (strlen(buff) == 0)
{
closesocket(sock);
break;
}
memset(buff,0,255);
}
As you see - very not good :( So is there a way to change 'while' into some kind of 'when'. So the client program would sleep until it get's messages?
Something like:
when (you_got_message() == true)
{
function that responses to server
}
Doe's this make any sence? :)
Pls help me and the world :D