#!/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;
}
}
}
}
####
#!/usr/bin/perl
use IO::Socket::INET;
use strict;
my $sock = IO::Socket::INET->new(
PeerAddr => '192.168.1.10',
PeerPort => 1001,
Proto => 'tcp',
#Broadcast => 1,
#LocalAddr => '192.168.1.11',
);
while(chomp(my $txt = <>)){
print $sock $txt;
$sock->flush;
}
##
##
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =
+¿ =