#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $HOST = $ARGV[0]; my $PORT = $ARGV[1]; my $NUM_FORKS = $ARGV[2]; die "usage: $0 HOST PORT NUMFORKS\n" unless ($PORT && $HOST && $NUM_FORKS); sub new_conn { my $conn = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $HOST, PeerPort => $PORT, ) or die "cannot connect: $@\n"; return $conn; } my @pids = (); sub annihilate { die("Died with Ctrl-C"); } for (my $i = 0; $i < $NUM_FORKS; $i++) { $pids[$i] = fork(); die "fork failed: $@\n" unless (defined $pids[$i]); if ($pids[$i] > 0) { # parent } else { # child my $c = new_conn(); print $c "NICK 0\nUSER foo bar baz :testclient\n"; while(<$c>) { if ($_ =~ /PING (.*)/) { print $c "PONG $1\n"; } } exit(1); } } $SIG{INT} = \&annihilate; while () { ; } exit 0;