NetBurner 3.5.6
PDF Version
UDP Sockets

UDP Sockets Example Application

Overview

This NetBurner application demonstrates bidirectional UDP communication using the UDP Sockets API. The application can send and receive UDP packets with another host on a network, making it useful for network communication testing and development.

Features

  • Bidirectional Communication: Send and receive UDP packets simultaneously
  • Interactive Configuration: Runtime configuration of destination IP and port
  • Multi-threaded: Separate task for receiving packets to ensure real-time processing
  • Serial Interface: Uses MTTTY serial port program for user interaction
  • Network Stack Integration: Built on NetBurner's networking framework

Architecture

The application consists of two main components:

Main Task (UserMain)

  • Initializes the network stack and waits for DHCP
  • Prompts user for destination IP address and port number
  • Creates a UDP socket for sending packets
  • Handles user input and sends UDP packets
  • Runs at standard priority

Receive Task (UdpReceiveTask)

  • Monitors specified port for incoming UDP packets
  • Creates a separate UDP socket for receiving
  • Processes incoming packets and displays their contents
  • Runs at higher priority than main task for responsive packet handling

Usage

Setup

  1. Connect to the device using MTTTY serial port program
  2. Ensure the device is connected to a network with DHCP

Runtime Configuration

  1. When prompted, enter the destination IP address of the UDP server
  2. Enter the port number (used for both sending and receiving)
  3. The application will create sockets and start the receive task

Operation

  • Type messages and press Enter to send UDP packets
  • Incoming packets are automatically displayed with source information
  • The application runs continuously until reset

Example Session

Application: UDP Sockets Example
NNDK Revision: [version]
Enter the UDP Server destination IP address: 192.168.1.100
Enter the source/destination port number: 12345
Sending/Receiving with host 192.168.1.100: 12345
UdpReceiveTask monitoring port 12345
Listening for UDP packets on port 12345
Enter data and hit enter to send.
Hello World
Sending "Hello World" using UDP to 192.168.1.100 : 12345
Received a UDP packet with 11 bytes from : 192.168.1.100
Response message

Technical Details

Dependencies

  • NetBurner NNDK (NetBurner Network Development Kit)
  • Standard C libraries: stdlib.h, string.h, stdio.h
  • NetBurner specific: init.h, system.h, udp.h, utils.h

Socket Management

Task Management

  • Main task priority: MAIN_PRIO
  • Receive task priority: MAIN_PRIO - 1 (higher priority)
  • Stack allocation: USER_TASK_STK_SIZE for receive task

Buffer Limitations

  • Maximum message size: 80 characters
  • Input buffer: 80 bytes for user input
  • Receive buffer: 80 bytes for incoming packets

Testing with External Applications

The application can be tested with:

  • NetBurner Java Example: Companion Java application for UDP testing
  • NetBurner UDP Terminal Program: Specialized terminal for UDP communication
  • Standard UDP Tools: Any application capable of sending/receiving UDP packets

Alternative API

Note: NetBurner also provides a C++ Class-based API using UDPPacket for object-oriented UDP handling.

Error Handling

The application includes error checking for:

  • UDP socket creation failures
  • Network initialization issues
  • DHCP timeout scenarios

Failed socket creation will cause the application to enter an infinite loop, requiring a system reset.

Development Notes

  • System diagnostics are enabled for debugging (should be removed for production)
  • 5-second timeout for network initialization
  • Null-termination is manually added to received packets
  • The application uses NetBurner's proprietary IP address formatting (I)