Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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;


Comment on Re^2: UDP Client Multiple servers
Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-07-30 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls