Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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
Replies are listed 'Best First'.
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 surveying the Monastery: (7)
As of 2015-08-01 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls