... elsif( SERVICE_RUNNING == $State ) { our $sock = new IO::Socket::INET(LocalPort => MYPORT, Reuse => 1, Listen => 5 ) or LOGDIE "can't create local socket: $@\n"; INFO "Accepting connections on Port ", MYPORT, "..."; our $client; $SIG{'CHLD'} = sub { wait(); }; # No Zombies my $pid = fork(); if ($pid == 0) { # Child while ( 1 == 1) { if ( $client = $sock->accept() ) { INFO "Connection from ", $client->peerhost(), ":", $client->peerport(); while (<$client>) { unless ($_ =~ /^[\w.-_\s]+$/) { print $client "Invalid Input!. Type [h]elp for help\n"; next; } chomp; $_ =~ s/\r$//; DEBUG "Got command: $_"; my $output = get_output($_); print $client $output; } INFO "Client " . $client->peerhost() . " has disconnected."; } } } else { while ( SERVICE_STOP_PENDING != Win32::Daemon::State() ) { sleep 5; } #### We are done so close down... ### Win32::Daemon::State( SERVICE_STOPPED ); Win32::Daemon::StopService(); INFO "Need to go, bye"; kill(9, $pid); exit; } }