Brian Raven wrote:

> Well the example in 'perldoc IO::Select' seems to provide a basic
> skeleton that can be fleshed out. However, as I am feeling generous
> today for some reason, as well as suggesting that you RTFM, I have
> fleshed it out a little.
> 
> ----------------------------------------------------
> use strict;
> use warnings;
> use IO::Select;
> use IO::Socket;
> my $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 9876, ReuseAddr
> => 1);
> my $sel = new IO::Select( $lsn );
> while (my @ready = $sel->can_read) {
>     foreach my $fh (@ready) {
>       if ($fh == $lsn) {
>           my $new = $lsn->accept;
>           $sel->add($new);
>           my $host = $new->peerhost;
>           print "[Accepting connection from $host]\n";
>       } else {
>           my $line = <$fh>;

I would normally not be doing <> IO on a socket.  sysread is
the better way to go IMO.

>           $line =~ s/\s+$//;
>           if ($line =~ /^quit/i) {
>               my $host = $fh->peerhost;
>               $sel->remove($fh);
>               $fh->close;
>               print "Connection from $host terminated\n";
>           }
>           else {
>               print $fh->peerhost, " said '$line'\n";
>               print $fh "You said: '$line'\n";

This echo print can lock you up.  can_write should be used to
determine if write is prudent.  This is why a Qing system is
probably the way to go for multi-client single server setup.

>           }
>       }
>     }
> }
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to