Multicast Example Application
Overview
This example program demonstrates how to add a NetBurner device to a multicast group for sending and receiving UDP packets. The application allows you to specify a multicast IP address and port number, then send data by typing it in MTTTY or view received data from other devices in the same multicast group.
- Note
- This example only supports IPv4 multicast communication.
Features
- Join IPv4 multicast groups
- Send UDP packets to multicast group
- Receive and display UDP packets from multicast group
- Interactive console interface for user input
- Concurrent packet listening and sending
Application Components
main.cpp
The main NetBurner application written in C++ that:
- Prompts user for multicast group port number
- Prompts user for multicast IP address (administratively-scoped local IPv4 range: 239.0.0.0 to 239.255.255.255)
- Creates a background task to listen for incoming multicast packets
- Allows interactive sending of text messages to the multicast group
- Handles graceful shutdown and unregistration from multicast group
MultiRx.py
A Python utility script for testing multicast reception:
- Listens on multicast group 239.1.2.3 port 35123
- Receives and displays UDP packets from the multicast group
- Useful for testing the NetBurner application from a PC
How It Works
- Initialization: The application starts by enabling system diagnostics and prompting for configuration
- Configuration: User enters the port number and multicast IP address
- Task Creation: A background task (MultiReaderMain) is created to handle incoming packets
- Packet Reception: The background task registers with the multicast group and continuously listens for packets
- Packet Sending: The main loop allows user to type messages that are sent as UDP packets to the multicast group
- Shutdown: Empty input triggers unregistration and shutdown
Usage Instructions
NetBurner Device Setup
- Flash the application to your NetBurner device
- Connect to the device via MTTTY
- When prompted, enter the multicast port number (e.g., 35123)
- Enter a valid multicast IP address in the range 239.0.0.0 to 239.255.255.255
- The device will join the multicast group and display confirmation
Sending Messages
- Type any text message and press Enter to send it to the multicast group
- The message will be broadcast to all devices in the same multicast group
- Enter an empty string (just press Enter) to shutdown the listener
Receiving Messages
- The application automatically displays received packets with:
- Packet size in bytes
- Source IP address
- Packet contents
Testing with Python Script
- Run the MultiRx.py script on a PC connected to the same network
- The script will listen for packets on multicast group 239.1.2.3 port 35123
- Send messages from the NetBurner device to see them received by the Python script
Technical Details
Key Functions
RegisterMulticastFifo(): Registers to receive multicast packets
UnregisterMulticastFifo(): Unregisters from multicast group
UDPPacket: Class for creating and parsing UDP packets
OSTaskCreatewName(): Creates background task for packet reception
Multicast IP Address Ranges
The application uses administratively-scoped local IPv4 multicast addresses:
- Range: 239.0.0.0 to 239.255.255.255
- These addresses are reserved for organizational use and don't route across the internet
Threading Model
- Main thread handles user input and packet sending
- Background thread (MultiReaderMain) handles packet reception
- Uses OS_FIFO for inter-thread communication
Important Notes
- Only IPv4 multicast is supported
- The application requires a reset to restart after shutdown
- System diagnostics are enabled (consider removing for production)
- The hardcoded IP address 239.1.2.3 overrides user input in the current code
Troubleshooting
- No packets received: Verify all devices are on the same network and using the same multicast address/port
- Application hangs: Check network connectivity and firewall settings
- Build errors: Ensure all NetBurner SDK libraries are properly linked
Dependencies
- NetBurner SDK
- Standard C++ libraries
- NetBurner multicast support library