#!/usr/bin/perl -w
# client1.pl - a simple client
#----------------

use Socket;

# initialize host and port
my $host = shift || 'localhost';
my $port = shift || 80;
my $document = shift || '/';

$EOL = "\015\012";
$BLANK = $EOL x 2;

my $proto = (getprotobyname('tcp'))[2] || 6;

# get the port address
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);

# create the socket, connect to the port
socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect(SOCKET, $paddr) or die "connect: $!";
$ofh = select(SOCKET); $| = 1; select($ofh);

print SOCKET "GET $document HTTP/1.0" . $BLANK;

vec($rin='', fileno(SOCKET), 1) = 1;
select($rin, undef, undef, 20) || die "no response from server.";

my $line;
while ($line = <SOCKET>) {
	print $line;
}
close SOCKET or die "close: $!";