Advertisement
Infra_HDC

stepik-last-20200729-001

Jul 29th, 2020
1,676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.71 KB | None | 0 0
  1. use strict;
  2. use IO::Socket;
  3. setpgrp(0,0);
  4. my $general_ppid = $$;  # print $general_ppid."\n";
  5. my $server = IO::Socket::INET->new(
  6.     LocalPort => 8080,
  7.     Type      => SOCK_STREAM,
  8.     ReuseAddr => 1,
  9.     Listen    => 10)
  10. or die "Can't create server on port 8080 : $@ $/";
  11. while (my $client = $server->accept()) {
  12. my $child = fork();
  13. if ($child) { close($client); next }
  14. if (defined $child) {
  15. close( $server );
  16. $client->autoflush(1);
  17. my $message;
  18. do {
  19.   if (defined (my $message1 = <$client>))
  20.   { chomp $message1; $message = $message1; }
  21.   else { last ; }
  22.   if ($message eq "exit") { kill -2, 0 }
  23.   else { print $message."\n"; }
  24. } while (1);
  25. close( $client );
  26. exit;
  27. } else { die "Can't fork^ $!"; }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement