#!/usr/bin/perl use Socket; use URI::Escape; my $port = 8765; my $addr = '127.0.0.1'; socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "socket:$!"; setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) or die "setsockopt: $!"; bind(SERVER, sockaddr_in($port, inet_aton($addr))) or die "bind: $!"; listen(SERVER, SOMAXCONN) or die "listen: $!"; sub writeLog { my $str = shift; print "$str\n"; } while(1){ my $paddr; for(; $paddr = accept(CLIENT, SERVER); close CLIENT){ my $line = ; my $cmd = substr $line, 0, 5; if($cmd eq "START") { my $url = substr $line, 6; writeLog("START $url"); do { my $res = `lwp-request "$url"`; @array = split(" ", $res); writeLog("$res sleep 10"); sleep 10; writeLog('wakeup'); } while ($array[0] eq 'CONTINUE'); } writeLog('close client connection'); close(CLIENT); } }