#!/usr/bin/perl -w use strict; use IO::Select; use IO::Socket; my $pipefile = shift || "./genpipe"; my $serverPort = shift || 4509; syswrite(STDOUT,"Before listenSocket\n"); my $listenSocket = IO::Socket::INET->new(LocalPort => $serverPort, Listen => 50, Proto => 'tcp', Reuse => 1, timeout => 60*60, ); die "Cannot set up listening socket!\n" unless $listenSocket; while (1) { my $incoming = $listenSocket->accept(); $incoming->autoflush(1); syswrite(STDOUT,"ACCPETED -> $incoming\n"); while ($incoming->connected()) { open(PIPE,"<$pipefile") or die "Cannot open pipe $pipefile. $!\n"; if (! $incoming->connected() ) # The above line will always be the same # as the initial check before the loop, so # I never get to the code block just below, # and I lose the data on this iteration. { close(PIPE); syswrite(STDOUT,"EXECUTING 'last' STATEMENT!\n"); last; } syswrite(STDOUT,"OPENED PIPE\n"); syswrite(STDOUT,"** just before reading pipe\n"); syswrite(STDOUT,"just before write to channel\n"); map {syswrite($incoming,$_)} (); syswrite(STDOUT,"just after write to channel\n"); close(PIPE); } }