Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

connect() connection timeout

by perlthirst (Scribe)
on Dec 12, 2008 at 08:22 UTC ( [id://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?

Replies are listed 'Best First'.
Re: connect() connection timeout
by BrowserUk (Patriarch) 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 (Abbot) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-19 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found