#!/usr/bin/perl # code creates a "globalcity" newspaper front page # by sawad brooks # august 15, 2002 use Socket; use URI; # my $abs_url = URI->new_abs($rel_url, $base_url); @space = ("www.nytimes.com", "www.guardian.co.uk", "www.asahi.com"); # open(FILE,">global.html") || die("Cannot Open File"); # select(FILE); $| = 1; select(STDOUT); select(STDOUT); $| = 1; print "Content-type: text/html\n"; print "\n"; srand; $cityindex = int(rand 3); $ctr = 0; $offset = 0; print ""; print " "; while ($ctr < 3) { print "
"; # print "connecting $space[$cityindex] ..."; @stream = &GetHTTP($space[$cityindex], "/"); foreach $s (@stream) { print $s; # print "."; } print "
"; $cityindex++; if ($cityindex > 2) { $cityindex = 0; } $ctr++; $offset = $offset + 200; } print "THREE POINTS IN SPACE - WITH HELP FROM SASSEN"; exit; sub GetHTTP { local($hostname, $doc) = @_; # print STDOUT $hostname, $doc; local($port, $iaddr, $paddr, $proto, $line, @output); # we ignore the "host:port" notation, and assume http=80 everytime. socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die "socket(): $!\n"; $paddr = sockaddr_in(80, inet_aton($hostname)); connect(SOCK, $paddr) || die "connect(): $!\n"; select (SOCK); $| = 1; select(STDOUT); # send the HTTP-Request print SOCK "GET $doc HTTP/1.0\n\n"; # now read the entire response: do { $line = } until ($line =~ /^\r\n/); @output = ; close(SOCK); return @output; }