Here's some working code on my main machine.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11161465 use warnings; use IO::Socket::Multicast; my $s = IO::Socket::Multicast->new or die $@; $s->mcast_if( 'tybalt' ); $s->mcast_dest(scalar sockaddr_in(9999, inet_aton('239.1.1.1'))); my $me = qx(hostname) =~ tr/\n//dr; open my $la, '<', '/proc/loadavg' or die "$! opening loadavg"; while(1) { seek $la, 0, 0; my $data = "$me " . localtime . ' ' . <$la>; print "data: $data"; $s->mcast_send($data) or die "$! on send"; sleep 1; }
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11161465 use warnings; use IO::Socket::Multicast; my $s = IO::Socket::Multicast->new(LocalPort => 9999) or die $@; $s->mcast_add('239.1.1.1', 'tybalt') or die "group $!"; while(1) { $s->recv(my $data, 1024); print $data; }

This machine has TWO interfaces, one of which is named 'tybalt' (sort of like 'eth0' but different :). This code would not work until I added the interface name in the appropriate places. On another similar machine that has only one interface, the interface name was not required. Neither was the interface name required on a raspberry pi running Manjaro.

So my working theory is that if you have more than one interface, interface names are required.
Interestingly, omitting the interface name from the mcast_add method for the two interface machine does not cause an error, it just doesn't get the multicast messages.

Two machines are running ArchLinux and one is running Manjaro. All three can multicast to each other, and all three are receiving all multicasts.

Note also that none of my machines would take a string in mcast_dest, nor would they take a string as the second argument of mcast_send.


In reply to Re: How to properly send and receive data from multicast? by tybalt89
in thread How to properly send and receive data from multicast? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.