Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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?

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 (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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://729877]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-11-21 19:32 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (310 votes). Check out past polls.