Hello
Where is your debugging code? I mean: perl gives you all the means of tracking down the errors, yet I don't see you used any of them. Let me explain:
- You need to put #!/usr/bin/perl -w in the first line to get warnings.
- You should use strict.
- You should always check return values.
- When an error occurs, print out the error (using $!):
if (connect(S,$s)) {
print "connected to $host\n";
print S "GET \/ HTTP\/1.0\n\n";
read(S,$data,100) || die "Error Reading: $!\n";
close(S);
} else { die "connect failed: $!\n" }
- Read the perldocs carefully as the socket function clearly states: You should "use Socket", and the read page states: Returns the number of bytes actually read, 0 at
end of file, or undef if there was an error. . So, at the read line, you should do my $lines = read(...); die "Error Reading: $!
\n" unless defined $lines;
- Check out the LWP and LWP::Simple for doing HTTP get, and save yourself the headache.
- If you really want to do raw protocol level communication, then use the IO::Socket::INET for a clearer more OO interface to sockets.
Hope this helps,,,