#!C:/perl/bin/perl -w use strict; use warnings; my $cvs_version = sprintf "%d.%03d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/; 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, Timeout => .1, # this seems to have no improvement on my problem... #Blocking => 1, # if this is enabled Perl dies with "Bad file descriptor" ) or die "can't connect to port $port on $host: $!"; my $num = 'a'; #just proving that ioctl has infact changed this to undef after running... $num = ioctl($handle, 0x8004667e, 1); print "ioctl return code was [$num]\n"; #with or without the ioctl statement, reading from the socket... #... eventually blocks if nothing is there to be read... $handle->autoflush(1); print STDERR "[Connected to $host:$port]\n"; die "can't fork: $!" unless defined($kidpid = fork()); if ($kidpid) { # parent copies the socket to standard output $| = 1; #set STDOUT to non-buffered to demonstrate that two way... # ...communication is possible up until there is nothing left to read. my $buff; while (1){ my $num = sysread($handle, $buff, 4); #if there are zero bytes waiting, the sysread appears ... if ($num >= 4) { #... to block, and even blocks the child thread from writing to $handle... print $buff; } else { print "buffer is [$num] bytes big\n"; } sleep 1; } warn "Read from buffer stopped...\n"; kill("TERM" => $kidpid); } else { # child copies standard input to the socket while (defined ($line = )) { chomp $line; warn "echo before send: [$line]\n"; print $handle "$line\n"; warn "echo after send: [$line]\n"; } } exit;