#!/usr/bin/perl # simple perl client to download homepage use Socket; use FileHandle; my ($SERVER) = @ARGV; my $saddr; my @buffer; my ($x, $y, $i, $j); # utility socket(cfd,AF_INET,SOCK_STREAM,getprotobyname('tcp')) || die "error"; $saddr = sockaddr_in (80, inet_aton("$SERVER")); # $SERVER can be ip or name connect(cfd,$saddr) || die "connection error"; cfd->autoflush(1); print cfd "GET /index.html\n"; # without the autoflush line above, this print will be buffered. # autoflush is not needed when doing the low level IO (sysread/write). @buffer = ; # read all available lines print STDOUT @buffer; #foreach (@buffer) { print $_, "\n"; } # not needed, since \n already there close(cfd);