First, I'm new to perl

I'm attempting to create a proxy server that will listen to data coming in on one socket (A) and then be able to provide that incoming data to multiple client sockets (Bs) but need some help in implementation.

My problem is I'm going to have 3 loops:
1: Receive data on A
2: Listen for new client connections
3: Provide data received on A to each B client socket

I've tried:
1: Forking with pipes from parent to child and even grandchildren that ended up providing data to the B clients in a round robin fashion
2: Broadcast UDP - clients cannot read from broadcast IP address

Currently I am trying to use IO::Select where the child will add each accepted client socket to an array. In my ideal world the parent would read through each item in the array and write the same data to each socket. But the parent doesn't have access items written by the child in this scenario.

use IO::Socket; use IO::Select; use IO::Handle; $A = new IO::SOCKET::INET (LocalHost => 'localhost', LocalPort => 1234, Type => SOCK_STREAM, Proto => "tcp", Reuse => 1, Listen => 5) or die "A Server socket couldn't be created: $@\n"; $B_listen = new IO::SOCKET::INET (LocalHost => 'localhost', LocalPort => 5555, Type => SOCK_STREAM, Proto => "tcp", Reuse => 1, Listen => 5) or die "B Server socket couldn't be created: $@\n"; my $B_clients = new IO::Select(); my $pid = fork(); if ($pid) { #PARENT while($A_sock = $A->accept()) { #Will only have 1 connection while(defined($buf=<$A_sock>)){ my @client_set = $B_clients->can_write; foreach my $client (@client_set) { print $client $buf; } } } } else { #CHILD while($B_sock = $B_listen->accept()) { $B_clients->add($B_sock); } }
Any ideas or different strategies?

In reply to Proxy Server Help by PhillyR

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.