Code working but not after 1 day
Hi all,
First, I am new to this forum :)
I've just started playing with the C language. And I wanted to create a script which will keep my game server online. The script is working fine. It checks if the port is in use and then sends a players status command to the server. If the server doesnt respond the process will get killed and restarted.
After a while, lets say 1 day the script doesnt know anymore if the server is online it keeps killing the process over and over even when it is online.
I thought that it may be had to do with the sockets which I need to close or something, to many sockets opened?
Here is a piece of code:
Code:
peer.sin_family = AF_INET;
from = atoi("****");
check = 0;
peer.sin_addr.s_addr = resolv("***.***.***.***");
peer.sin_port = htons(from);
printf("All done, Please sit back while I'll keep an eye on your server.\n");
while( 1 < 3) {
sleep(PLENTYOFSEC);
sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sd < 0) std_err();
if(sendto(sd, "\\status\\", 8, 0, (struct sockaddr *)&peer, sizeof(peer))< 0) std_err();
if(timeout(sd, TIMEOUT) < 0 ) {
printf("\nServer IS NOT running!!! Count: %hu \n\n ", check);
system("killall process.exe");
system("sh restart.sh");
check ++;
} else {
if (scan == check) {
fputs(".", stdout);
}
}
close(sd);
}
Thanks in advance.