Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: UDP Client Multiple servers

by BrowserUk (Pope)
on Oct 11, 2012 at 15:55 UTC ( #998487=note: print w/ replies, xml ) Need Help??


in reply to UDP Client Multiple servers

What happens if you add use strict; at the top of your code and prefix your variables with my?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong


Comment on Re: UDP Client Multiple servers
Download Code
Re^2: UDP Client Multiple servers
by adwald (Initiate) on Oct 11, 2012 at 16:22 UTC

    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;

      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-08-30 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls