Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use IO::Socket;
- setpgrp(0,0);
- my $general_ppid = $$; # print $general_ppid."\n";
- my $server = IO::Socket::INET->new(
- LocalPort => 8080,
- Type => SOCK_STREAM,
- ReuseAddr => 1,
- Listen => 10)
- or die "Can't create server on port 8080 : $@ $/";
- while (my $client = $server->accept()) {
- my $child = fork();
- if ($child) { close($client); next }
- if (defined $child) {
- close( $server );
- $client->autoflush(1);
- my $message;
- do {
- if (defined (my $message1 = <$client>))
- { chomp $message1; $message = $message1; }
- else { last ; }
- if ($message eq "exit") { kill -2, 0 }
- else { print $message."\n"; }
- } while (1);
- close( $client );
- exit;
- } else { die "Can't fork^ $!"; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement