8 print "$$ Server started\n";; # do a "top -p -H $$" to monitor server
10 our @clients : shared;
13 my $server = new IO::Socket::INET(
20 my $num_of_client = -1;
26 $client = $server->accept;
27 } until ( defined($client) );
29 my $peerhost = $client->peerhost();
30 print "accepted a client $client, $peerhost, id = ", ++$num_of_client, "\n";
31 my $fileno = fileno $client;
32 push (@clients, $fileno);
33 #spawn a thread here for each client
34 my $thr = threads->new( \&processit, $client, $fileno, $peerhost )->detach();
39 my ($lclient,$lfileno,$lpeer) = @_; #local client
41 if($lclient->connected){
43 #print $lclient "$lpeer->$_\n";
44 print "clients-> @clients\n";
46 foreach my $fn (@clients) {
47 open my $fh, ">&=$fn" or warn $! and die;
53 #close filehandle before detached thread dies out
55 #remove multi-echo-clients from echo list
56 @clients = grep {$_ !~ $lfileno} @clients;