#!/usr/bin/perl -w
use Socket;
use IO::Socket;

use constant SIZE => 10;

if ((defined($ARGV[0]))&&($ARGV[0] =~ /(\d+)/)) {
    $port = $1;
} else {
    $port = 5001;
}

my $S;
my $C;
my $res;

$S = IO::Socket::INET->new(Listen => 1, Reuse => 1, LocalHost => inet_ntoa(INADDR_ANY), LocalPort => $port, Proto => 'tcp');
die "Could not create socket: $!\n" unless $S;
while (1) {
    $C = $S->accept();

    while ($C->connected()) {
	$res = "";
	for (1..SIZE) {
	    $res .= (int(1000 * rand)) . " ";
	}
	$res .= "\n";
	$C->send($res, 0);
	sleep 1;
    }
    close($C);
}
close($S);
