All pastes #408199 Raw Edit

Mindphuck

public text v1 · immutable
#408199 ·published 2007-03-24 17:48 UTC
rendered paste body
#!/usr/bin/perl
#basic perl chat script
use strict;
use IO::Socket;
my $paddr = @ARGV;
$paddr = inet_aton("$paddr");

my $pid = fork;
if($pid == 0) {
	my $sock = IO::Socket::INET->new(	PeerHost => "$paddr",
																PeerPort => "6264",
																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 => "6264",
														Proto => "tcp",
														Listen => "1",
														Reuse => "1"
														) or die "cannot create socket: $!";
	my $newsock = $sock->accept();
	my @response = <$newsock>;
	print "- Response -\n";
	foreach (@response){
		print "$_";
	}
}