#!/usr/bin/perl #use threads; #use threads::shared; #use DBI; use IO::Socket::INET; use IO::Select; use constant { PORT => 1001, }; use strict; my $lsn = IO::Socket::INET->new( LocalPort => PORT, Listen => 1, Proto => 'tcp', ); print 'Waiting for connections on '.PORT."\n\n"; my $sel = IO::Select->new($lsn); my @users; while(my @available = $sel->can_read){ foreach my $fh (@available){ if($lsn == $fh){ #The listen socket has a connection my $new = $fh->accept; print 'Connection accepted from'.$fh->connected."\n"; $sel->add($new); #push(@users,$new); }else{ local $/; my $data = <$fh>; if($fh->connected){ print $fh->connected.' = '.$data."\n"; }else{ $sel->remove($fh); $fh->close; } } } }