Here is an example I cooked really quick that illustrates how you can redirect stderr to all non-blocking sockets: It looks like a broadcasting chat server.
use Socket; use Fcntl; use IO::Socket; use IO::Select; my $serv = IO::Socket::INET->new(LocalPort => 9001, Reuse => 1, Listen + => 10) or die "Cannot open server: $!\n"; nonblock($serv); my $sel = IO::Select->new($serv); pipe $MYSTDERR, $MYWRITE; *STDERR = $MYWRITE; $sel->add($MYSTDERR); while(1){ for my $sock ($sel->can_read(0)) { if($sock == $MYSTDERR){ my $line = <$sock>; print $line; for my $s ($sel->handles()){ if($s != $MYSTDERR and $s != $serv){ print $s $line; } } } elsif($sock == $serv){ my $new = $serv->accept(); nonblock($new); $sel->add($new); bcast($new, "New Connection"); } else { # this is a client reading my $line = <$sock>; if($line){ chomp($line); bcast($sock, "Data: $line"); } else { bcast($sock, "Connection Dropped"); $sel->remove($sock); } } } } sub bcast{ my $sock = shift; warn sprintf "[%s:%s] @_\n", $sock->peerhost, $sock->peerport; } sub nonblock { my $socket = shift; my $flags; $flags = fcntl($socket, F_GETFL, 0) or die "Can't get flags for socket: $!\n"; fcntl($socket, F_SETFL, $flags | O_NONBLOCK) or die "Can't make socket nonblocking: $!\n"; }
I hope it helps,,,

Aziz,,,


In reply to Re: Sending STDOUT to Multiple Sockets by abstracts
in thread Sending STDOUT to Multiple Sockets by rapier1

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.