I am attempting to use the "Multiplexing Using Select" Code on page 195 of the Advanced Perl Programming Guide, however, I am unable to see any results from the given code.

I am sending data to the specified port, but nothing is being printed to screen. What am I missing? Am I just completely off?

I am attempting to be able to send data from multiple clients to a single server and have the data sent printed to screen.

Thanks!

#!/usr/bin/perl -lw # # # Define Modules use IO::Socket; use IO::Select; #Establish Server Socket $main_sock = new IO::Socket::INET (LocalHost => 'C285', LocalPort => 9325, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Socket could not be created. Reason: $!" unless $main_sock; #Process Received Data $readable_handles = new IO::Select(); $readable_handles->add($main_socket); while (1) { # Select() blocks until a socket is ready to be read ($new_readable) = IO::Select->select($readable_handles, undef, und +ef, 0); # If it comes here, there is atleast one handle # to read from. foreach $sock (@$new_readable) { if ($sock == $main_socket) { $new_sock = $sock->accept(); # Add to the list, and go back to select because the # new socket may not be readable yet. $readable_handles->add($new_sock); } else { # It is an ordinary client socket, ready for reading. $buf = <$sock>; if ($buf) { print $buf; } else { # Client closed socket. Need to do the same thing # here and remove it from $readable_handles list. print "Position = 6\n"; $readable_handles->remove($sock); clost($sock); } } } }

In reply to Multiplexing using Select by matt.schnarr

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.