http://www.perlmonks.org?node_id=534926


in reply to (Seemingly) Broken interactions between Net::Server and IO::Pipe?

Slimmed down my code to an (obvious) test case... which (thankfully) fails.
#!/usr/bin/perl -w # server package Server; use strict; use base qw(Net::Server::Fork); my $server = bless { server => { port => 8097, log_level => 4, }, }, 'Server'; $server->run(); exit; sub process_request { my $self = shift; my $x = Feeder->new(); my $line = $x->get_line(); print "Line = $line\n"; } package Feeder; use strict; use IO::Pipe; sub new { my $class = shift; my $pipe = IO::Pipe->new(); $pipe->reader('cat', '/home/ben/foo/client'); my $self = { PIPE => $pipe, }; return bless $self, $class; } sub get_line { my $self = shift; my $fh = $self->{PIPE}; return scalar(<$fh>); }
And, the corresponding client,
#!/usr/bin/perl -w # client use strict; use IO::Socket::INET; my $sock = IO::Socket::INET->new(PeerHost => 'localhost', PeerPort => 8097, Proto => 'tcp', ); die "Unable to connect" unless $sock->connected(); while (<$sock>) { print "Got: >$_<\n"; }
I can't see that there's anything wrong with any of the above, although I'd love to be convinced otherwise...