#!/usr/bin/perl use IO::Socket; # Make our connections my $ns1 = new IO::Socket::INET (PeerAddr => shell, PeerPort => 1200, Proto => 'tcp' ) or die "Couldn't create socket: $!\n"; # Now let's fork the client so we can read and write my $pid = fork(); $fork_errlvl = 1 unless defined $pid; # If we weren't able to fork... die "Error forking client: Reason: $!\n" if $fork_errlvl != 0; if ($pid) { write_sock(); waitpid($pid, 0); } else { read_sock(); } sub write_sock { foreach my $key (@ARGV) { print $ns1 "$key\n"; sleep(1); } close($ns1); } sub read_sock { while (my $line = <$ns1>) { chomp($line); print "$line\n"; if ($line eq 'CAIO') { close($ns1); } } }