I did try using Select - in fact I even started by modifying this very example:)

I had a couple questions in regards to using IO::Select - the first being, how do I select() specifically which client/process I want to speak to, and more importantly, when used in this manner, will the socket/connection be bidirectional (can I both read and write?).

(see ... ??? comments in code snippet below)

#this sets up $main_sock to handle multiple connections...??? $readable_handles = new IO::Select(); $readable_handles->add($main_sock); #this returns an array of readable (and writeable) #handles/connections...??? $new_readable) = IO::Select->select($readable_handles, undef, undef+, +0); #So now I can iterate through this array just like I would #for any other, except it is an array of "connections"... foreach $sock (@$new_readable) { #in the case that ($sock == $main_sock) this means that #I need to listen for & add any new connections to the #list of $readable_handles, but why not to $new_readable #as well...??? if ($sock == $main_sock) { $new_sock = $sock->accept(); $readable_handles->add($new_sock); } else { $buf = <$sock>; if ($buf) { #does the line $readable_handles->can_write() mean that #these handles are not bidirectional...??? print "$buf\n"; my @sockets = $readable_handles->can_write(); #print $sock "You sent $buf\n"; foreach my $sck(@sockets){print $sck "$buf\n";} } else { $readable_handles->remove($sock); close($sock); } } }

This may be a useful implementation, but if you gurus out there could give me the play-by-play on how the code above operates it would help me out tremendously..

Thanks again... more to come...


In reply to Re^2: sockets and such in Perl by scotchfx
in thread sockets and such in Perl by scotchfx

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.