my $socket = new IO::Socket::INET ( LocalHost => $hostAddr, LocalPort => $hostPort, Proto => 'tcp', Type => SOCK_STREAM, Listen => SOMAXCONN, Reuse => 1 ) or die "*** Can't create server socket. ($!) ***\n" unless $socket; print "*** Server listening on $hostAddr:$hostPort ... :-) ***\n"; my $allClients = new IO::Select($socket); my @activeClients; while (@activeClients = $allClients->can_read()) { foreach my $client (@activeClients) { if ($client eq $socket) { my $newClient = $socket->accept(); # accept the connection $allClients->add($newClient); # add it to the handler print "*** ".$newClient->peerhost.":".$newClient->peerport." has just connected. ***\n"; } else { my $nval = $client->recv(my $request, $maxBuffer, 0); if (!defined($nval) || !length($request)) { print "*** Connection has been closed. ***\n"; my $h = 0; while ($activeUsers[$h]) { if ($activeUsers[$h]->{'handle'} == $client) { splice(@activeUsers,$h,1); } $h++; } $allClients->remove($client); $client->close(); next; } } } }