ugly_legs has asked for the wisdom of the Perl Monks concerning the following question:

I'm building a function that connects to a remote host and tests for the availability of a audio/video clip. I'm using IO::Socket::INET to connect to a remote host, write a few lines across the socket, and then read the response (200 OK, 404, etc.) If I do this:
$dst_server = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $stream_port);
It will not connect up to the specified host on the specified port. If I explicitly name the host and port, then everything is fine:
$dst_server = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "stream.foo.com", PeerPort => "554");
I've debugged this a bit and I have a print statement before I try to connect up to the server where I print out the values of $host and $stream_port and they are correct.

I suppose I've goofed on the syntax somewhere?

Thanks,
ugly_legs

Edit: added <code> tags, link to CPAN. larsen

Replies are listed 'Best First'.
Re: IO::Socket::INET grief
by DamnDirtyApe (Curate) on May 21, 2002 at 17:35 UTC

    I'm having trouble reproducing your problem. Namely, I can't get the code to fail. I modified it slightly to something I knew existed, and tried:

    use IO::Socket ; my $host = "www.example.com" ; my $stream_port = "80" ; $dst_server = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $stream_port) or warn "Error with vars: $@\n"; $dst_server = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "www.example.com", PeerPort => "80") or warn "Error with strings: $@\n";

    This yields no errors for me. Probably doesn't help you a whole lot, but maybe you can work from it...


    _______________
    D a m n D i r t y A p e
    Home Node | Email
Re: IO::Socket::INET grief
by Aristotle (Chancellor) on May 21, 2002 at 19:21 UTC
    Could you post some more code please. That lone line of each example isn't very helpful.

    Makeshifts last the longest.

Re: IO::Socket::INET grief
by tadman (Prior) on May 22, 2002 at 02:40 UTC
    ($host eq "stream.foo.com" && $stream_port eq "554") || die "Typo?";
    There might be something ugly in your variables.

    #!/usr/bin/perl -w use strict;