use IO::Socket; use Net::hostent; $PORT = 9000; $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; while ($client = $server->accept()) { $client->autoflush(1); my $pid = fork(); if ($pid) { #parent my $hostinfo = gethostbyaddr($client->peeraddr); printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost; print "Being Handled by child with pid $pid]\n"; wait(); } else { #child print $client "Welcome to $0.\n"; system('./sleep.pl'); } close $client; }