I had a need to test multicast between different points on our network, so I wrote some Perl. The server runs on a stable box (a server, go figure) and the client runs on a laptop I can move around. There is also a thin Windows client.
NOTE: On Linux/UNIX if you're not using your default interface for multicast, you'll need to do route add -net 224.0.0.0 netmask 240.0.0.0 dev eth1. Doing ping -t 1 -c 2 224.0.0.1 should return a list of multicasting clients on the network.
Contents |
Server
The IO::Socket::Multicast module isn't standard, so you'll need to cpan it. Also, this requires IO::Interface if you want to use the mcast_if function.
#!/usr/bin/perl
use IO::Socket::Multicast;
use strict;
$|=1;
my $MTESTADDRESS = "226.1.2.3";
my $MTESTPORT = "2010";
my $msock=IO::Socket::Multicast->new(Proto=>'udp',PeerAddr=>"$MTESTADDRESS:$MTESTPORT",ReuseAddr=>1);
$msock->mcast_if("eth0");
while(1) {
my $time=localtime(time);
$msock->mcast_send($time,"$MTESTADDRESS:$MTESTPORT") || die "$!\n";
print ".";
sleep(10);
}
Client
Perl
#!/usr/bin/perl
use IO::Socket::Multicast;
use strict;
my $MTESTADDRESS = "226.1.2.3";
my $MTESTPORT = "2010";
my $msock=IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>"$MTESTPORT",ReuseAddr=>1);
$msock->mcast_add($MTESTADDRESS,"eth0") || die "Could not join $MTESTADDRESS on $MTESTPORT\n";
while(1) {
my $buf;
$msock->recv($buf,1024);
print ".$buf\n";
}
Windows
Unfortunately, there's a non-standard DLL and a few OCXs that are needed to make the Windows version work.
Grab the binary here.