Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: UDP Client Multiple servers

by adwald (Initiate)
on Oct 11, 2012 at 16:22 UTC ( #998489=note: print w/replies, xml ) Need Help??

in reply to Re: UDP Client Multiple servers
in thread UDP Client Multiple servers

I found the answer to my problem. I needed to eval whether a response was received in an amount of time and escape out if not.

eval { local $SIG{ALRM} = sub { die 'Timed Out'; }; alarm 1; #receive response $handle->recv($newmsg, 1024) or die; $packet = Net::DHCP::Packet->new($newmsg); $data = $packet->toString(); close $handle; alarm 0; }; close $handle;

Replies are listed 'Best First'.
Re^3: UDP Client Multiple servers
by zwon (Monsignor) on Oct 12, 2012 at 06:30 UTC

    That's not really a good idea. You could just set timeout option on the socket after creating it:

    use Socket qw(SO_RCVTIMEO); use POSIX qw(:errno_h); ...; my $timeout = pack 'L!L!', $sec, $usec; $handle->sockopt(SO_RCVTIMEO, $timeout); ...; my $res = $handle->recv(...); unless(defined $res) { if($! == EAGAIN or $! == EWOULDBLOCK) { say "time out"; } }

      Does the Timeout parameter to IO::Socket::INET->new() have the same effect as the sockopt() method?

      Maybe another WTDI.

        Not really, despite documentation for IO::Socket::INET says "Timeout value for various operations", Timeout parameter is only used by connect method of IO::Socket, it doesn't affect recv in any way.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998489]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2016-10-21 13:35 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.