Sometimes it is easier to just give a standard working example, rather than explain why a snippet isn't working. I'm guessing it's your while(1)...but I didn't try your code.

A working server:

#!/usr/bin/perl use Net::hostent; use IO::Socket::INET; use IO::Select; my $s = new IO::Select; $IP = '192.168.0.1'; $PORT = 15005; my $server = new IO::Socket::INET( LocalAddr => $IP, LocalPort => $PORT, Proto => 'tcp', Listen => SOMAXCONN, ReuseAddr => 1 ); # Listen for multiple connections. $s->add($server); $s->add(\*STDIN); print ">> $0 accepting connections on $PORT\n"; while ( my @ready = $s->can_read() ) { foreach my $fh (@ready) { # if($fh == \*STDIN){ $in_text = <>; # foreach my $fh (@ready){ print "$in_ip >> $in_text";} # } if ( $fh == $server ) { my $new = $server->accept; $s->add($new); my $hostinfo = inet_ntoa( $new->peeraddr ); # Show IP that just connected. print "CONN >> $hostinfo\n"; } else { #my $in_ip = inet_ntoa($fh->peeraddr);#error-prone my $in_ip = $fh->peeraddr ? inet_ntoa( $fh->peeraddr ) : "unknown"; my $in_text = scalar <$fh>; # If the client closes the connection, #remove this socket, but #keep the script running, waiting/serving #other connections. if ( $in_text ne "" ) { } else { $s->remove($fh); $fh->close; print "DISCONN >> $in_ip\n"; } # Every time "TEXT\n" is sent, display this print "$in_ip >> $in_text"; } } } print "Program end.\n"; #What its meant to do: Listen on a port #for connections, allow multiple #connections at once (hence the foreach() #forking), and when the client #quits, successfully closes the connection.

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Multiplexing using Select by zentara
in thread 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.