#!/usr/bin/perl #use strict; use IO::Socket; use constant MYPORT => 2000; my $sock = ''; my $client = ''; $sock = new IO::Socket::INET(LocalPort => MYPORT, Reuse => 1, Listen => 5) or die "can't create local socket: $@\n"; # Zombies verhindern $SIG{'CHLD'} = sub { wait; }; my $PaPID; my $ChPID; print "Accepting connections on Port ", MYPORT, "...\n"; while(defined($sock)){ #while ($client = $sock->accept()) #{ # Verbindung ist aufgebaut close $new_sock; my $new_sock = $sock->accept() or next; next if fork != 0; #print "Accepted connection from ", #$client->peerhost(), ":", $client->peerport(), "\n"; my $text; $SIG{CHLD} = sub { wait; }; $PaPID = $$; $ChPID = fork(); if($ChPID == 0){ while (<$new_sock>) { if($_ eq "help\r\n"){ print $new_sock "wuuuussaaa\n"; }elsif($_ eq "xx\r\n"){ print $new_sock "xx? what a crap ...\n"; }else{ print $new_sock "unknow command -> "; print $new_sock $_, "\n"; } } kill 15,$PaPID; exit; } } close $sock;