#!/usr/bin/perl use strict; use IO::Socket; use constant MYPORT => 2345; use POSIX ":sys_wait_h"; #$| = 1; my $sock = ''; my $client = ''; my ($pid, $PID, $waitpid, ); $sock = new IO::Socket::INET(LocalPort => MYPORT, Reuse => 1, Listen => 5) or die "can't create local socket: $@\n"; #sub sigchldHandler { # $waitpid = wait(); # $SIG{CHLD} = \&sigchldHandler; #} #$SIG{CHLD} = \&sigchldHandler; $SIG{'CHLD'} = sub { wait(); $client ->close; }; print "Accepting connections on Port ", MYPORT, "...\n"; while ($client = $sock->accept()) { print "Accepted connection from ", $client->peerhost(), ":", $client->peerport(),; if (fork() == 0) { $PID = $$; print ", PID:$PID\n"; while (<$client>) { chomp; print $client scalar(reverse($_)), "\n"; print $client "$PID\n"; } } }