rendered paste body#!/usr/bin/perl
#perl script that repeats a string - can be delocalised over networks
use strict;
use IO::Socket;
my $pid = fork;
if($pid == 0) {
my $sock = IO::Socket::INET->new( PeerHost => "localhost",
PeerPort => "337",
Proto => "tcp",
) or die "cannot create socket: $!";
print "Successfully connected.\n\n";
print "- Message -\n";
while(my $string = <STDIN>){
if ($string =~ /^end$/){
exit;
}
else{
print $sock "$string";
}
}
close $sock;
}
else {
my $sock = IO::Socket::INET->new( LocalHost => "localhost",
LocalPort => "337",
Proto => "tcp",
Listen => "1",
Reuse => "1"
) or die "cannot create socket: $!";
my $newsock = $sock->accept();
my @response = <$newsock>;
print "\n- Response -\n";
foreach (@response){
print "$_";
}
}