use strict; use IO::Select; use IO::Socket::INET; $SIG{CHLD} = 'IGNORE'; my $one_print = shift @ARGV || 0; my $listener = IO::Socket::INET->new(Listen => 1, LocalPort => 8080); my $select = IO::Select->new($listener); while( my @ready = $select->can_read ){ foreach( @ready ){ if( $_ == $listener ){ my $sock = $listener->accept; my $pid = fork; if( defined $pid && $pid == 0 ){ while( 1 ){ my $line = <$sock>; last unless defined $line; if( $line =~ /^QUIT/ ){ print $sock "Goodbye\n"; $sock->close; last; }elsif( $one_print ){ print $sock $line, ".\n"; }else{ print $sock $line; print $sock ".\n"; } } # while read loop exit(0); } } } }