simeon2000 has asked for the wisdom of the Perl Monks concerning the following question:
What I'd like to do is to say that if I don't recieve input from the client in, say, 10 seconds, to close the socket. I've tried setting "Timeout" on the listening socket, but all that seems to do is close the listen socket if it doesn't recieve a connection after 10 seconds, which is obviously not what I want.
Here's an example of the code, and what I want to do in comments:
I'm positive there's a module or something out there to help me with this. Would someone please guide this poor soul in the right direction?# For each connection we accept while (my $con = $lsock->accept) { # This holdes the Child PID I believe my $child; # Fork a kid or die baby die "Can't fork: $!\n" unless defined ($child = fork()); if ($child == 0) { # Close the child's listen socket, we don't need it $lsock->close if $lsock; ### # Here's the problem I believe. On while $line = <$con> # I'd like to do "last if no data recieved for $x seconds." ### # For each line of input from the connection while (my $line = <$con>) { # remove newlines, bad data, etc. $line = filter($line); unless ($line) { print $con $error; next } # I determine what to send back by what they send in if ($line eq 'QUIT' ) { print $con "+OK Sayonara\n"; last; } elsif ($line eq 'GET DATA') { print $con "+OK Sending DATA\n", $lib->get_data, "\n.\n"; next; } else { print $con $error; next } } # Close this connection $con->close if $con; exit(0); } else { # We're the parent, we've already handed the connection off $con->close; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket::INET Dangling Connections
by rpc (Monk) on Feb 21, 2001 at 00:24 UTC | |
by Anonymous Monk on Feb 21, 2001 at 02:07 UTC |