  #!/usr/bin/perl  my $port = 1962;  use Socket;  use strict;  my $tcp = getprotobyname('tcp');  socket(Server, PF_INET, SOCK_STREAM, $tcp) or die "socket: $!";  setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l",1)) or warn "setsockopt: $!";  bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!";  listen(Server, SOMAXCONN) or die "listen: $!";  for( ; accept(Client, Server); close(Client) ) {	my $remote_sockaddr = getpeername(Client);	my (undef, $iaddr) = sockaddr_in($remote_sockaddr);	my $peername = gethostbyaddr($iaddr,AF_INET) || "localhost";	my $peeraddr = inet_ntoa($iaddr) || "127.0.0.1";	if( $peeraddr eq "127.0.0.1" ) { # respond only to the local machine		chomp($_ = <Client>);		my( $method, $url, $proto, undef) = split;		if( $url eq "/quit" ) {			close(Server);			exit 0;		} elsif( $url =~ /(\/tests\/.*)\?run.cgi/ ) {			my $filename = "Docs" . $1;			run_fit( $filename, "tempout.htm" );			output_file( "tempout.htm" );		} else {			$url = "/index.htm" if( $url eq "/" );			output_file( "Docs" . $url );		}	}  }  sub run_fit {	my ($filename, $outputfilename) = @_;	my $classpath = ".";	$classpath .= ";third-party/junit.jar";	open THIRDPARTY, "dir third-party |" or die $!;	while( <THIRDPARTY> ) {		chomp( $_ );		$classpath .= ";third-party/" . $1 if( $_ =~ /(\w*\.jar)/ );	}    close THIRDPARTY;	system( "java -cp $classpath urbansim.tests.fit.FileRunner $filename $outputfilename" );  }  sub output_file {	my ($filepath) = @_;	print Client "HTTP/1.0\n";	if( $filepath =~ /\.gif/ ) {		print Client "Content-type: image/gif\n";	} elsif( $filepath =~ /\.jpg/ ) {		print Client "Content-type: image/jpeg\n";	} else {		print Client "Content-type: text/html\n";	}	print Client "\n";	local $/; undef $/; # globble whole files	open INPUT, "<$filepath" or die $!;	binmode( INPUT );	my $content = <INPUT>;	close INPUT;	print Client $content;	print Client "\n";  }