#!/usr/bin/perl

use IO::Socket;

$Token			= "abc";


@ports = ("3383","3384","3385","3386","3387","3388");
my @BenchmarkSearch	= (
	"Paris",
	"suck",
	"big",
	"huge",
	"breast",
	"little",
	"teen",
	"young",
	"spears",
	"small",
	"spiderman",
	"love",
	"tiny",
	"blow",
	"sex",
	"xxx",
	"fat",
	"top",
	"slut",
	"dirty",
	"tits",
	"girlfriend",
	"bitch",
	"sister",
	"jamba",
	"job",
	"anderson",
	"kylie",
	"britney",
	"shakira",
);




while(1){


	open(LOG,"+>>load.txt");

	print LOG "Before0: [" .Time()."] # ".Load()."\n";
	print "Before: [" .Time()."] # ".Load()."\n";

	foreach my $search (@BenchmarkSearch) {

		foreach my $port (@ports) {

			my $PhexConnection = IO::Socket::INET->new( 
						PeerAddr	=> "127.0.0.1",
						PeerPort	=> $port,				# port vom phex server->org: ###########
						Proto		=> 'tcp',
						Timeout		=> 5 ) or warn "PhexProxy::IO->CreatePhexConnection(): Can't connect to TCP Socket for CLIENT SOCKET->Phex: Phex DOWN? $!\n";
				
			$in =<$PhexConnection>;			# empfange die "hi" message; remove diesen eintrag, wenn keine hi message mehr vom server gesendet werden
			
			$id = rand();
			print $PhexConnection "find $id 0 52000000 Any $Token $search -filetype: .jpg\r\n";	
			$infrom =<$PhexConnection>;
			### print "IN: $infrom\n";
			close($PhexConnection);

		}# foreach my $port (@ports) {

	}; # foreach my $search (@BenchmarkSearch) {

	print LOG "After00: [" .Time()."] # ".Load()."\n";
	print "After: [" .Time()."] # ".Load()."\n";

	sleep 5;

	print LOG "After05: [" .Time()."] # ".Load()."\n";
	print "After5: [" .Time()."] # ".Load()."\n";

	sleep 5;

	print LOG "After10: [" .Time()."] # ".Load()."\n";
	print "After10: [" .Time()."] # ".Load()."\n";

	sleep 10;

	print LOG "After20: [" .Time()."] # ".Load()."\n";
	print "After20: [" .Time()."] # ".Load()."\n";

	sleep 10;

	print LOG "After30: [" .Time()."] # ".Load()."\n";
	print "After30: [" .Time()."] # ".Load()."\n";

	sleep 10;

	print LOG "After40: [" .Time()."] # ".Load()."\n";
	print "After40: [" .Time()."] # ".Load()."\n";

	close LOG;

	sleep 5;

}; # while(1){

sub Time(){

	my ( $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst ) = localtime(time);
	$year = $year+1900;
	$mon = $mon + 1;

	if ( length($mon) == 1 ) {
		$mon = "0". $mon;
	};
	if ( length($mday) == 1 ) {
		$mday = "0". $mday;
	};
	if ( length($sec) == 1 ) {
		$sec = "0". $sec;
	};
	if ( length($min) == 1 ) {
		$min = "0". $min;
	};
	if ( length($hour) == 1 ) {
		$hour = "0". $hour;
	};
	   
	return $year ."-". $mon ."-". $mday .' '. $hour .':'. $min .':'. $sec;

}; # sub Time(){


sub Load(){

	open(FILE, "</proc/loadavg" ) or warn "$0->ReadFile(/proc/loadavg): IO ERROR: $!\n";
	flock(FILE, 2);
	{ 	local $/		= undef;	# Read entire file at once
		$FileContent	= <FILE>;   # Return file as one single `line'
       };  
	close FILE;

	my ($Load1,$Load2,$Load3,undef)	= split(" ", $FileContent);

	return $Load1;

}; # sub Load(){





exit;
