Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

connect() connection timeout

by perlthirst (Scribe)
on Dec 12, 2008 at 08:22 UTC ( #729877=perlquestion: print w/ replies, xml ) Need Help??
perlthirst has asked for the wisdom of the Perl Monks concerning the following question:

Is there any way to achieve this with out using thread or fork?

Comment on connect() connection timeout
Re: connect() connection timeout
by BrowserUk (Pope) on Dec 12, 2008 at 08:44 UTC

    May need a little work :)

    #! perl -slw use strict; use threads; use Connector qw[ connect ]; my $con1 = connect( 'server1' ) or die "Couldn't connect to server1"; async{ $con1->send( "I'm alive") while sleep 2; }; my $con2; 1 until( $con2 = connect( 'server2' ) ); while( my $data = $con2->read ) { ## process $data }

    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.
Re: connect() connection timeout
by zwon (Monsignor) on Dec 12, 2008 at 19:09 UTC
    You can use IO::Socket, it allows you to set timeout:
    use strict; use warnings; use IO::Socket::INET; my $sock = IO::Socket::INET->new( PeerAddr => 'X.X.X.X', PeerPort => '80', Proto => 'tcp', Timeout => 3, ); die $! unless $sock;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-07-25 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (172 votes), past polls