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.
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:
- Get a UDP socket.
- Set the IP Time-To-Live (TTL) appropriately.
- Set the default interface from which multicast datagrams should be sent.
- Send data to the application's multicast address and port number.
- 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:
- Get a UDP socket.
- Bind to the application's port number.
- Join the application's multicast address group.
- Receive.
- 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
- RtCreateEvent
- RtCreateTimer
- RtPrintf
- RtSetEvent
- RtSetThreadPriority
- RtSetTimerRelative
- RtWaitForSingleObject
Supported Windows API
Winsock API