Multicast Sample

The Multicast sample can be run as a sender or receiver. The sender periodically sends a multicast frame, while the receiver subscribes to the corresponding multicast group and waits to receive the multicast frames sent by the sender.

To test the Loopback feature in TCP/IP, you could run both the sender and receiver versions of the Multicast.rtss image on the same computer.

Note: This sample can also be run on Windows.

Run as a Multicast Sender

As a multicast sender, the program creates a repeatable timer and the timer handler routine, Broadcast, does the following:

  1. Get a UDP socket.
  2. Set the IP Time-To-Live (TTL) appropriately.
  3. Set the default interface from which multicast datagrams should be sent.
  4. Send data to the application's multicast address and port number.
  5. Shut down and close the socket when complete.

Note: The sender does not have to join a multicast group.

Run as a Multicast Receiver

As a multicast receiver, the program creates a child thread. The child thread routine, ChildThread_high, does the following:

  1. Get a UDP socket.
  2. Bind to the application's port number.
  3. Join the application's multicast address group.
  4. Receive.
  5. Shut down and close the socket when complete.

Note: The receiver is not required to set a default interface for multicast datagrams.

Multicast Sender Usage:

RTSSrun Multicast.rtss m=224.5.6.7 i=IP_address f=IF_address [options]

Multicast Receiver Usage:

RTSSrun Multicast.rtss m=224.5.6.7 i=IP_address u [options]

Note: All Multicast command-line options are case-sensitive.

Option

Description

p=

Port number (default is 9999)

m=

Multicast IP address in dot notation

f=

IP address of the default interface for sending Multicast packets

n=

Multicast message content (default is EmptyName)

r=

Rate of Multicast in seconds (default is 5 seconds)

i=

Local IP address in dot notation.

u

When this option is used, the Multicast sample is run as a receiver. When not used, the Multicast sample is run as a sender.

t=

Time-To-Live value (default is 1)

k=

Kill all receivers

/?

Displays usage

The Multicast sender prints a trace every time it sends a multicast packet:

=========================
Multicast sample
=========================
Broadcasting... Set IF: <192.168.200.1:1C8A8C0>. Broadcast complete!
Broadcasting... Set IF: <192.168.200.1:1C8A8C0>. Broadcast complete!
Broadcasting... Set IF: <192.168.200.1:1C8A8C0>. Broadcast complete!
Broadcasting... Set IF: <192.168.200.1:1C8A8C0>. Broadcast complete!
The Multicast Receiver prints a trace every time it receives a multicast packet:
=========================
Multicast sample
=========================
Received <EmptyName>.
Received <EmptyName>.
Received <EmptyName>.

EmptyName is the default message sent by the Multicast sender in the multicast frames. You can use the n= option to change this.

APIs Referenced

RTAPI

Supported Windows API

Winsock API