I am trying to multicast messages in a local network using IO::Socket::Multicast module. Here's my attempt:
sender.pl
use strict; use warnings; use IO::Socket::Multicast; my $socket = new IO::Socket::Multicast() or die "cannot create socket: + $!\n"; $socket->mcast_send("this is multicast", '239.1.1.1:9999') or die "err +or: $!\n"; $socket->close();
receiver.pl
use strict; use warnings; use IO::Socket::Multicast; my $socket = new IO::Socket::Multicast( LocalPort => 9999, ) or die "cannot create socket: $!\n"; my $res = $socket->mcast_add('239.1.1.1'); print "subscribe status: $res\n"; my $data; $socket->recv($data, 1024); print "received: $data\n"; $socket->close();
The problem is that the receiver couldn't receive the message, it just kept waiting.
Additionally, I tested the program on 2 machines, interchanging the roles of sender and receiver and probed them using Wireshark Only one machine displayed "membership report group 239.1.1.1" in the info column, while the other had different group IP, even though both machines printed "subscribe status: 1" in the command line. The machine that seemed to be correct is a Windows virtual machine hosted by the other Windows machine.
Why is this happening and how to multicast properly? Any help would be appreciated.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |