NetBurner 3.5.6
PDF Version
Multicast

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

  1. Initialization: The application starts by enabling system diagnostics and prompting for configuration
  2. Configuration: User enters the port number and multicast IP address
  3. Task Creation: A background task (MultiReaderMain) is created to handle incoming packets
  4. Packet Reception: The background task registers with the multicast group and continuously listens for packets
  5. Packet Sending: The main loop allows user to type messages that are sent as UDP packets to the multicast group
  6. Shutdown: Empty input triggers unregistration and shutdown

Usage Instructions

NetBurner Device Setup

  1. Flash the application to your NetBurner device
  2. Connect to the device via MTTTY
  3. When prompted, enter the multicast port number (e.g., 35123)
  4. Enter a valid multicast IP address in the range 239.0.0.0 to 239.255.255.255
  5. The device will join the multicast group and display confirmation

Sending Messages

  1. Type any text message and press Enter to send it to the multicast group
  2. The message will be broadcast to all devices in the same multicast group
  3. 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

  1. Run the MultiRx.py script on a PC connected to the same network
  2. The script will listen for packets on multicast group 239.1.2.3 port 35123
  3. 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

  1. No packets received: Verify all devices are on the same network and using the same multicast address/port
  2. Application hangs: Check network connectivity and firewall settings
  3. Build errors: Ensure all NetBurner SDK libraries are properly linked

Dependencies

  • NetBurner SDK
  • Standard C++ libraries
  • NetBurner multicast support library