| Revision 2 (by moose, 2008/11/28 19:56:31) |
initial import |
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::Multicast;
use IO::Select;
my $s = IO::Socket::Multicast->new( Proto => 'udp', LocalPort => 2000, ReuseAddr => 1);
$s->mcast_loopback(1);
$s->mcast_add('226.1.1.2') || die "Couldn't set group: $!\n";
my $select = IO::Select->new( );
$select->add($s);
$select->add(\*STDIN);
my @ready;
while(@ready = $select->can_read) {
for my $fh (@ready) {
if($fh == \*STDIN) {
my $text = <STDIN>;
chomp $text;
$s->mcast_send($text, '226.1.1.2:2000');
}
else {
my $text;
$fh->recv($text, 1024) || die "ack";
print $text."\n";
}
}
}