K
Ken Browning
(Source at end of question)
Given this source, I am able to connect to the server, but when I try
to send data to the child process, it never seems to get there...any
suggestions?
use IO::Select;
use IO::Socket;
##############################################################
my ($host, $port, $kidpid, $handle, $line);
unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) =@ARGV;
$handle=IO::Socket::INET->new (Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "can't connect to $port on $host: $!";
$handle->autoflush(1);
print STDERR "[Connected to $host:$port]\n";
#die "can't fork: $!" unless defined($kidpid=fork());
$kidpid = open (KID_TO_WRITE, "|-");
unless (defined $kidpid) {
die "can't fork: $!"
}
if($kidpid){ #parent process
print $handle "0=1.3\n";
printf("sent: 0=1.3\n");
while (defined ($line = <$handle>)) {
chomp($line);
printf("RECV: %s\n",$line);
printf( KID_TO_WRITE "test %s\n",$line);
print KID_TO_WRITE "[this is a test]" ;
printf( "printed to child process...: %s\n",$line);
}
kill ("TERM" => $kidpid);
}else{ #child process
printf( STDERR "Inside child process...\n");
while (defined ($line = <STDIN>)) {
print STDERR "Inside loop : $line";
print STDERR "SEND: $line";
}
printf( STDERR "Exiting child process...\n");
exit;
}
exit;
Given this source, I am able to connect to the server, but when I try
to send data to the child process, it never seems to get there...any
suggestions?
use IO::Select;
use IO::Socket;
##############################################################
my ($host, $port, $kidpid, $handle, $line);
unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) =@ARGV;
$handle=IO::Socket::INET->new (Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "can't connect to $port on $host: $!";
$handle->autoflush(1);
print STDERR "[Connected to $host:$port]\n";
#die "can't fork: $!" unless defined($kidpid=fork());
$kidpid = open (KID_TO_WRITE, "|-");
unless (defined $kidpid) {
die "can't fork: $!"
}
if($kidpid){ #parent process
print $handle "0=1.3\n";
printf("sent: 0=1.3\n");
while (defined ($line = <$handle>)) {
chomp($line);
printf("RECV: %s\n",$line);
printf( KID_TO_WRITE "test %s\n",$line);
print KID_TO_WRITE "[this is a test]" ;
printf( "printed to child process...: %s\n",$line);
}
kill ("TERM" => $kidpid);
}else{ #child process
printf( STDERR "Inside child process...\n");
while (defined ($line = <STDIN>)) {
print STDERR "Inside loop : $line";
print STDERR "SEND: $line";
}
printf( STDERR "Exiting child process...\n");
exit;
}
exit;