Getting website by "socket", program hangs

K

Knut

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
 
T

Tore Aursand

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

Scott W Gifford

(e-mail address removed) (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.
 
J

Joe Smith

Knut said:
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
 
K

Knut

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

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

.. K
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top