On Tuesday 06 July 2004 10:58, Werner Otto wrote:
> Hi All,
>
> I have the following script:

Hi Otto,

IIRC, you've posted nearly exactly the same question last thursday...

>
> #!/usr/bin/perl
> use IO::Socket;
>
> my $host=shift @ARGV or die 'need hostname';
> my $port=shift @ARGV or die 'need port number';
> my [EMAIL PROTECTED] or die 'need timeout';;

I think you want
  my $timeout = shift @ARGV or die 'need timeout';
here...otherwise you set $timeout to the number of arguments left in @ARGV, 
which is "1" at this point...

> my $socket=IO::Socket::INET->new(PeerAddr=> $host,
>         PeerPort => $port,
>         Proto => 'tcp',
>         Type => SOCK_STREAM

Bob Showalter told you last thursday that you're missing a comma between the 
"Type" and "Timeout" hash keys in your call to IO::Socket::INET->new(), but 
it's still missing in the source you posted now.
Did you try if it changes anything if you put this comma there? 

Replace
        Type => SOCK_STREAM
by
        Type => SOCK_STREAM,    # <-- HERE


>         Timeout => defined($timeout)?$timeout:1) or die "Can't talk to
> $host at $port";
>
[..]
> When doing this test on a connection that reponds it timesout after 1
> second. When I do this on a connection that is live but the port is
> incorrect it timesout after 1 second. My problem is when the pc is
> switched off it does not timeout after 1 second.
>
[..]

This sounds strange indeed - if I try to connect to a server that's not there, 
I get the error message after a quite short time (might be 1 second, but I'm 
not sure...), regardless of what I set "timeout" to...but maybe I'm not 
testing correctly.

Your problem might be the missing 'shift' above - for me it looks ok now...if 
it still does not work, I would take another look at the IO::Socket 
documentation - are you sure that the timeout you specify in the constructor 
is doing what you want (e.g. handling the timeout on connect vs. handling the 
timeout after connect)?

And please indicate next time that you already asked this question so that we 
don't have to search through the archives to find the problem's history...

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to