Great idea, tried the following on WinXP and it worked:
use strict; use warnings; use IO::Socket; use IO::Select; select( ( select( STDERR ), $| = 1 )[0] ); select( ( select( STDOUT ), $| = 1 )[0] ); my $server = IO::Socket::INET->new( LocalAddr => 'localhost', Listen => 5, Proto => 'tcp', ) or die( "No socket" ); my $port = $server->sockport(); print( STDERR "Created local TCP socket on port $port\n" ); if ( fork() ) { print "Parent live\n"; # wait for connection from just one child my $sock = undef; sleep( 1 ) while ( ! ( $sock = $server->accept() ) ); # create select object my $rsel = IO::Select->new(); $rsel->add($sock); while (1) { my $handles = scalar( $rsel->handles ); my ( $r ) = IO::Select::select( $rsel, undef, undef, 1 ); print( STDERR "Handles: $handles, " . ( $r ? scalar(@{$r}) : "undef" ) . " ready\n" ); if ( $r && @{$r} ) { foreach ( @{$r} ) { print( STDERR "[r]\n" ); my $buf = ""; sysread( $_, $buf, 1024 ); print( STDERR "[d:$buf:d]\n" ); } } else { print( STDERR "[b]\n" ); } } } else { print "Child live\n"; close( $server ); # make internet connection to server my $client = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => $port, Proto => 'tcp', ) or die( "No child connection" ); while (1) { print($client "HELLO!"); print( STDERR "[W]\n" ); sleep 3; } }

Outputs:

C:\Temp>perl -w deleteme.pl Created local TCP socket on port 1861 Parent live Child live Handles: 1, 1 ready [r] [d:HELLO!:d] [W] Handles: 1, undef ready [b] Handles: 1, undef ready [b] Handles: 1, undef ready [b] Handles: 1, 1 ready [r] [d:HELLO!:d] [W]

In reply to Re^2: IO::Select on an IO::Pipe not doing anything by monarch
in thread IO::Select on an IO::Pipe not doing anything by FLEB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.