IO-Socket-Multicast

 view release on metacpan or  search on metacpan

lib/IO/Socket/Multicast.pm  view on Meta::CPAN

  return send($sock,$data,0,$dest);
}

bootstrap IO::Socket::Multicast $VERSION;

1;

__END__

=pod

=head1 NAME

IO::Socket::Multicast - Send and receive multicast messages

=head1 SYNOPSIS

  use IO::Socket::Multicast;

  # create a new UDP socket ready to read datagrams on port 1100
  my $s = IO::Socket::Multicast->new(LocalPort=>1100);

  # Add a multicast group
  $s->mcast_add('225.0.1.1');

  # Add a multicast group to eth0 device
  $s->mcast_add('225.0.0.2','eth0');

  # now receive some multicast data
  $s->recv($data,1024);

  # Drop a multicast group
  $s->mcast_drop('225.0.0.1');

  # Set outgoing interface to eth0
  $s->mcast_if('eth0');

  # Set time to live on outgoing multicast packets
  $s->mcast_ttl(10);

  # Turn off loopbacking
  $s->mcast_loopback(0);

  # Multicast a message to group 225.0.0.1
  $s->mcast_send('hello world!','225.0.0.1:1200');
  $s->mcast_set('225.0.0.2:1200');
  $s->mcast_send('hello again!');

=head1 DESCRIPTION

The IO::Socket::Multicast module subclasses IO::Socket::INET to enable
you to manipulate multicast groups.  With this module (and an
operating system that supports multicasting), you will be able to
receive incoming multicast transmissions and generate your own
outgoing multicast packets.

This module requires IO::Interface version 0.94 or higher.

=head2 INTRODUCTION

Multicasting is designed for streaming multimedia applications and for
conferencing systems in which one transmitting machines needs to
distribute data to a large number of clients.

IP addresses in the range 224.0.0.0 and 239.255.255.255 are reserved
for multicasting.  These addresses do not correspond to individual
machines, but to multicast groups.  Messages sent to these addresses
will be delivered to a potentially large number of machines that have
registered their interest in receiving transmissions on these groups.
They work like TV channels.  A program tunes in to a multicast group
to receive transmissions to it, and tunes out when it no longer
wishes to receive the transmissions.

To receive transmissions B<from> a multicast group, you will use
IO::Socket::Multicast->new() to create a UDP socket and bind it to a local
network port.  You will then subscribe one or more multicast groups
using the mcast_add() method.  Subsequent calls to the standard recv()
method will now receive messages incoming messages transmitted to the
subscribed groups using the selected port number.

To send transmissions B<to> a multicast group, you can use the
standard send() method to send messages to the multicast group and
port of your choice.  The mcast_set() and mcast_send() methods are
provided as convenience functions.  Mcast_set() will set a default
multicast destination for messages which you then send with
mcast_send().

To set the number of hops (routers) that outgoing multicast messages
will cross, call mcast_ttl().  To activate or deactivate the looping
back of multicast messages (in which a copy of the transmitted
messages is received by the local machine), call mcast_loopback().

=head2 CONSTRUCTORS

=over 4

=item $socket = IO::Socket::Multicast->new([LocalPort=>$port,...])

The new() method is the constructor for the IO::Socket::Multicast
class.  It takes the same arguments as IO::Socket::INET, except that
the B<Proto> argument, rather than defaulting to "tcp", will default
to "udp", which is more appropriate for multicasting.

To create a UDP socket suitable for sending outgoing multicast
messages, call new() without arguments (or with
C<Proto=E<gt>'udp'>).  To create a UDP socket that can also receive
incoming multicast transmissions on a specific port, call new() with
the B<LocalPort> argument.

If you plan to run the client and server on the same machine, you may
wish to set the IO::Socket B<ReuseAddr> argument to a true value.
This allows multiple multicast sockets to bind to the same address.

=back

=head2 METHODS

=over 4

=item $success = $socket->mcast_add($multicast_address [,$interface])



( run in 0.581 second using v1.01-cache-2.11-cpan-39bf76dae61 )