http://www.perlmonks.org?node_id=982217

anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I am using the following code. I want to timeout and close the connection after 20 seconds, tried with alarms but nothing worked. Here is my code:
my $socket_resp = IO::Socket::INET->new(Blocking => 0, LocalPort => $c +omm_port, Proto => 'udp', Timeout => 2); $socket_resp->setsockopt(SO_RCVTIMEO, SO_RCVTIMEO, 10); print "Waiting for Response On Port $comm_port\n"; while (my $recieved_data = $socket_resp->getline()) { chomp($recieved_data); print "$recieved_data\n"; if ($recieved_data =~ m/^done/i) { last; } } $socket_resp->close();
alarms, and nothing else has worked. Can any one help.