All pastes #409230 Raw Edit

Mindphuck

public text v1 · immutable
#409230 ·published 2007-03-25 15:07 UTC
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 "$_";
	}
}