#!/usr/bin/perl use IO::Select; use IO::Socket; $sock = IO::Socket::INET->new(LocalHost => '127.0.0.1', LocalPort => 9999, Proto => 'tcp', Listen => 10, Reuse => 1) || die("Couldn't create socket: $!\n"); $s = IO::Select->new($sock); while(1) { foreach $client ($s->can_read(0)) { #check for all ready sockets if($client == $sock) { #if this is the main socket #we'll try to accpet a new connection $client = $sock->accept(); $s->add($client); } else { #this is a client socket if(eof($client)) { $s->remove($client); #remove them from the list if we've hit eof } $line = <$client>; print($client->peerhost, ": said $line"); } } }