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.


In reply to 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.