Loading ...
Sorry, an error occurred while loading the content.
 

Re: timeout for a socket?

Expand Messages
  • nvvikas
    ... http://search.cpan.org/~tomc/Socket-1.5/Socket.pm ... You may have to use the Object Oriented approach. Consider this code: use strict; use warnings; use
    Message 1 of 2 , Aug 18, 2008
      --- In perl-beginner@yahoogroups.com, "Brian" <brianlamere@...> wrote:
      >
      > The following does almost exactly what I want it to:
      >
      > socket(RSSH, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die
      > "couldn't open a socket? $!\n";
      > my $rsock = sockaddr_in (22, inet_aton($host));
      > if (connect(RSSH,$rsock)) {
      > close(RSSH);
      > return 1;
      > }
      >
      > problem, I can't figure out how to change the timeout. It's rather
      > long :) If something doesn't respond within just a couple seconds,
      > I'd rather assume it dead (after 3 tries, at least). I don't see any
      > sort of option for it at
      http://search.cpan.org/~tomc/Socket-1.5/Socket.pm
      >
      > Any suggestions?
      >
      > Thanks!
      > Brian
      >

      You may have to use the Object Oriented approach. Consider this code:
      use strict;
      use warnings;
      use IO::Socket::INET;

      my $sock = IO::Socket::INET->new(
      PeerAddr => '123.45.67.89', # IP address
      PeerPort => '2000', # port
      Timeout => '60' # timeout in seconds
      );
      # rest of your code using $sock.

      If you do not want to use the OO approach consider using Signals. You
      may use SIGALRM (sig alarm).
      YOu can read on this link for getting clarity on using Signals:
      http://www.perl.com/doc/manual/html/pod/perlfunc/alarm.html
      <http://www.perl.com/doc/manual/html/pod/perlfunc/alarm.html>

      Regs,
      viki
      Visit my Perl blog, for Perl tips & Perl tutorials
      <http://techdiary-viki.blogspot.com/>
      OR
      subscribe for email updates
      <http://www.feedburner.com/fb/a/emailverifySubmit?feedId=2119834&loc=en_\
      US>



      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.