NetBurner 3.5.6
PDF Version
UDP Echo

UDP C++ Packet Class Example

Overview

This application demonstrates how to send and receive UDP packets using NetBurner's C++ UDPPacket class. It provides a simple interactive interface for UDP communication between a NetBurner device and another host on the network.

Description

This example program will receive a UDP packet from another device or host computer and send a response. To run the example, connect a serial port from your PC to the debug serial port on your NetBurner device and run a terminal program such as MTTTY. On the PC, run the NetBurner UDP Terminal (be sure to set the IP address and port numbers to match). Send data from the NetBurner UDP Terminal, and observe that the packet is received in MTTTY. Then observe the response from the device in the NetBurner UDP Terminal.

The application creates a bidirectional UDP communication system that:

  • Accepts user input for destination IP address and port configuration
  • Sends UDP packets containing user-entered text data
  • Receives and displays incoming UDP packets from remote hosts
  • Uses NetBurner's UDPPacket C++ class for simplified UDP handling

Features

  • Interactive Configuration: Prompts user to specify destination IP address and port number via serial console
  • Dual Operation: Simultaneously sends and receives UDP packets on the same port
  • Real-time Display: Shows received packet data with source information
  • Multi-tasking: Uses separate tasks for sending and receiving operations
  • Network Ready: Waits for active network connection (DHCP) before starting

Architecture

Tasks

  1. UserMain Task:
    • Initializes network stack
    • Handles user input and configuration
    • Sends outgoing UDP packets
    • Creates the UDP reader task
  2. UdpReaderTask:
    • Monitors specified port for incoming packets
    • Processes and displays received data
    • Uses FIFO queue for packet management

Key Components

  • UDPPacket Class: NetBurner's C++ wrapper for UDP operations
  • OS_FIFO: Queue system for managing incoming packets
  • RegisterUDPFifo(): Registers port for UDP packet reception
  • Serial Interface: MTTTY terminal for user interaction

Usage

  1. Setup: Connect to the device using MTTTY serial port program
  2. Network: Ensure device has active network connection (DHCP)
  3. Configuration:
    • Enter destination IP address when prompted
    • Enter port number for both sending and receiving
  4. Operation:
    • Type messages and press Enter to send UDP packets
    • Incoming packets are automatically displayed with source information

Network Requirements

  • Active Ethernet connection
  • DHCP server for automatic IP configuration (or manual IP setup)
  • Network accessibility to destination host
  • Open UDP port for bidirectional communication

Compatible Hosts

The application can communicate with:

  • NetBurner Java UDP examples
  • NetBurner UDP terminal program
  • Any standard UDP client/server application
  • Custom UDP applications on PC or other devices

Technical Details

  • API: Uses NetBurner's UDPPacket C++ class (alternative to UDP sockets API)
  • Port Configuration: Same port used for both transmission and reception
  • Data Format: Text-based with null termination
  • Task Priority: Reader task runs at higher priority than main task
  • Timeout Support: Configurable timeout for packet reception (currently set to blocking)

Development Notes

  • System diagnostics are enabled (consider removing for production)
  • Application waits up to 5 seconds for network activation
  • Uses standard NetBurner NNDK (NetBurner Network Development Kit)
  • Includes proper error handling and packet validation