Thanks for the responses. I ended up using IO::Select, and got it working. Posting the code here for posterity/review. Thanks!
#!/usr/bin/perl
use IO::Socket;
use IO::Select;
my $socket =new IO::Socket::INET->new (
LocalHost => "<ipaddress>",
LocalPort => '<port>',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die("Couldn't create socket! $!\n") unless $socket;
my $select = new IO::Select($socket);
while(@ready = $select->can_read) {
foreach $fh (@ready) {
if($fh == $socket) {
$new = $socket->accept;
$select->add($new);
my $host= $new->peerhost;
print "[Accepting connection from $host]\n";
}
else {
my $line = <$fh>;
$line =~ s/\s+$//;
if($line =~/^quit$/i) {
my $host = $fh->peerhost;
$select->remove($fh);
$fh->close;
print "[Connection from $host terminat
+ed\n";
}
else {
print $fh->peerhost, " said '$line'\n"
+;
print $fh "You said: '$line'\n";
}
}
}
}
Thanks for all the help! With multiple servers sending at the same time, it keeps track (using peerhost) which host sends the message, and of course the message contents.