is there a way to keep it going, or restart automatically immediately after it dies?
I know you could setup a cron job, but it would be limited by how often it checks.. (5 mins, etc). is there any way to continually monitor it?
thanks
ah yes, indeed :)
well, the problem with a cron is that it would have to run every 5 seconds or something like that, I can't have the script down for even that long....
any other way to do it anyone can think of?
thanks!
$server = IO::Socket::INET->new(LocalPort => $server_port,
Type => SOCK_STREAM,
Reuse => 1,
Proto => 'tcp',
Listen => 128 ) ¦¦ die "couldn't be a server: $!\n";$readable_handles = IO::Select->new();
$readable_handles->add($server);
while (1) {
($new_readable) = IO::Select->select($readable_handles, undef, undef, undef);
foreach $sock (@$new_readable) {
if ($sock == $server) {
$new_sock = $sock->accept();
$readable_handles->add($new_sock);
} else {
$req = <$sock>;
if ($req) {
#do something with the socket
} else {
$readable_handles->remove($sock);
close ($sock);
}
}
}
}
The usual way of approaching this problem programmatically is to implement a PING procedure (from client to server).
So client sends server a ping byte every few seconds (say Y seconds). If server doesn't receive a ping in a time period of X + Y seconds, then server assumes the TCP/IP binding has dropped and restarts listening again.
There is no other way of detecting a binding drop if the server is not expecting activity (where a timeout would be appropriate). TCP/IP is designed in such a way that connections can go quiet for long periods of time. Setup a local network socket connection and pull the RJ45 out of the back of the client machine once you've established the socket binding and you'll see what I mean.
As others have stated, if you cannot implemnent an interval ping, then you have no option but restart via an outside app.
TJ
However, it's probably better to design your app better. Generally, socket applications listen() for the incoming connection, then fork() a child to accept() the request. The parent process just sits around and waits for connections.
Sean