Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to properly send and receive data from multicast?

by tybalt89 (Monsignor)
on Sep 02, 2024 at 05:30 UTC ( [id://11161511]=note: print w/replies, xml ) Need Help??


in reply to How to properly send and receive data from multicast?

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.

Replies are listed 'Best First'.
Re^2: How to properly send and receive data from multicast?
by Anonymous Monk on Sep 04, 2024 at 09:08 UTC

    I think the problem lies with my network. When I checked the network settings in the default gateway address, all IGMP related options had already been turned on. I tried your solution, but nothing changed. I also tried using another real machine to test, but the problem still persisted.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11161511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2025-07-13 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.