Getting website by "socket", program hangs

Discussion in 'Perl Misc' started by Knut, Jul 19, 2004.

  1. Knut

    Knut Guest

    Hey,

    I'm building a small linkchecker ++ to do some maintanence on a
    webserver I work with, but I have a problem.

    At about check nr. 13, the program hangs when getting a website from
    the web. (odin.dep.no/ud/norsk/aktuelt/taler/statsraad_b/032171-090195/index-dok000-b-n-a.html)

    My procedure is as follows:

    my $host="$_[0]";
    my $getstring="GET http://$_[1] HTTP/1.0\n\n";
    my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => 80,
    Proto => 'tcp') or print "ERRROR!!!";
    print $sock "$getstring";

    my $buf="";
    while($line = <$sock>) {
    $buf.=$line;
    }

    This works for the first few sites, but then hangs. Nothing seems to
    get read by the buffer at all...

    Can someone please help?

    Thanks in advance!

    .. Knut
     
    Knut, Jul 19, 2004
    #1
    1. Advertising

  2. Knut

    Tore Aursand Guest

    On Mon, 19 Jul 2004 03:33:45 -0700, Knut wrote:
    > my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => 80,
    > Proto => 'tcp') or print "ERRROR!!!";


    Why use 'IO::Socket::INET' in the first place? Isn't LWP::UserAgent (or
    it's derivates) adequate for your needs?


    --
    Tore Aursand <>
    "Programming is like sex, one mistake and you have to support it for
    the rest of your life." (Michael Sinz)
     
    Tore Aursand, Jul 19, 2004
    #2
    1. Advertising

  3. (Knut) writes:

    [...]

    > At about check nr. 13, the program hangs when getting a website from
    > the web. (odin.dep.no/ud/norsk/aktuelt/taler/statsraad_b/032171-090195/index-dok000-b-n-a.html)
    >
    > My procedure is as follows:
    >
    > my $host="$_[0]";
    > my $getstring="GET http://$_[1] HTTP/1.0\n\n";
    > my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => 80,
    > Proto => 'tcp') or print "ERRROR!!!";
    > print $sock "$getstring";
    >
    > my $buf="";
    > while($line = <$sock>) {
    > $buf.=$line;
    > }


    The proper line ending for an HTTP request is \r\n, so it's possible
    that one Web server doesn't recognized that you've finished sending
    the command. In general you don't start the request with "http://"
    either, but just send the path part of the request.

    It's also possible that there's a DNS problem causing a very long
    delay.

    Adding some debug statements to tell you exactly where it is hanging
    (during the connect? During the print? Waiting for the response?)
    would be helpful too, and looking at a tcpdump while you're doing this
    might be enlightening too. And changing the order of the sites, to
    see if it's the fact that it's the 13th or the site itself, would also
    give you useful information.

    Good luck!

    ----ScottG.
     
    Scott W Gifford, Jul 19, 2004
    #3
  4. Knut

    Joe Smith Guest

    Knut wrote:

    > Hey,
    >
    > I'm building a small linkchecker ++ to do some maintanence on a
    > webserver I work with, but I have a problem.
    >
    > At about check nr. 13, the program hangs when getting a website
    >
    > my $host="$_[0]";
    > my $getstring="GET http://$_[1] HTTP/1.0\n\n";
    > my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => 80,
    > Proto => 'tcp') or print "ERRROR!!!";
    > print $sock "$getstring";


    It's not clear to me whether you are explicitly using an HTTP proxy
    server or accidentally using a proxy server.

    If $host is a server set up to be a proxy, then $getstring is ok.
    If $host is the server and $_[1] is something like "/foo/index.html"
    then you should not be putting "http://" in the GET string.
    -Joe
     
    Joe Smith, Jul 19, 2004
    #4
  5. Knut

    Knut Guest

    It sure is... I just had no clue it exsisted ;)

    Thanks (to all), works perfectly now. (=

    .. K


    Tore Aursand <> wrote in message news:<>...
    > On Mon, 19 Jul 2004 03:33:45 -0700, Knut wrote:
    > > my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => 80,
    > > Proto => 'tcp') or print "ERRROR!!!";

    >
    > Why use 'IO::Socket::INET' in the first place? Isn't LWP::UserAgent (or
    > it's derivates) adequate for your needs?
     
    Knut, Jul 20, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    13
    Views:
    604
  2. Laszlo Nagy
    Replies:
    1
    Views:
    5,091
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,027
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    594
    Laszlo Nagy
    Feb 1, 2009
  5. Tim Shadel

    Gem hangs => TCPSocket.write hangs

    Tim Shadel, Jul 23, 2005, in forum: Ruby
    Replies:
    1
    Views:
    422
    Ville Mattila
    Jul 24, 2005
Loading...

Share This Page