use strict; use threads; use IO::Socket; # the port to listen on: my $PORT = 8989; # the number of threads to pre-spork: my $INITHREADS = 5; my $handle = IO::Socket::INET->new( LocalPort => $PORT, MultiHomed => 1, Type => SOCK_STREAM, Reuse => 1, Listen => 10) or die "Cannot open port $PORT: $!\n"; $handle->autoflush(1); for(1..$INITHREADS) { my $thr = threads->new(\&process)->detach(); } sleep(); # The parent thread sleeps forever. . . # You can potentially change this perma-sleep to # have the parent thread do dynamic thread management # but only if you don't detach() them. sub process { while(my $socklet = $handle->accept()) { # if you want to capture the IP address: # my $peerhost = $socklet->peerhost(); # Here you can do your stuff # I have the server talk to the client # via print $socklet and while(<$socklet>) } }