Example Path: examples/TCP/TcpResourceInfo
TCP Resource Information
Overview
This NetBurner embedded application demonstrates system resource monitoring capabilities by providing real-time information about TCP buffers, network sockets, and file descriptors. The application is designed to help developers understand and monitor network resource usage in embedded systems.
Features
The application provides three main monitoring functions:
- System Buffer Monitoring: Display the number of free system buffers
- Socket Resource Tracking: Show available network sockets and file descriptors
- Dynamic Resource Testing: Create and close listening sockets to demonstrate resource consumption
Both a serial menu and a live web dashboard are provided.
Web Dashboard
In addition to the serial menu, the application serves a web page that shows the same resource counts updating live (about once per second). Browse to the device's IP address to view it. The page reports free buffers, free TCP sockets, and free extra file descriptors, and includes a button that holds a listening socket open so you can watch the free-socket count drop and recover in real time.
The live values are produced on the device by CPPCALL handlers in main.cpp that write straight to the HTTP socket with fdprintf (the table on first load, and a small JSON fragment served from data.html for the periodic refresh). The page uses a self-contained stylesheet and plain JavaScript – no framework or CDN.
System Requirements
- NetBurner Hardware
- NetBurner SDK (tested with revision 3.5.4)
- Active network connection
Application Structure
Core Functions
The application utilizes three key system functions for resource monitoring:
Menu System
The application provides an interactive serial menu with the following options:
- Show free buffers and sockets - Displays current resource availability
- Add a listen socket, display info, and close the socket - Demonstrates resource consumption by creating a temporary listening socket on port 10000
- Get extra fd count - Shows the count of extra file descriptors
Usage
- Compile and deploy the application to your NetBurner device
- Connect to the device via serial terminal
- The application will automatically initialize the network and display the menu
- Enter the number corresponding to your desired action:
- Press '1' to view current resource status
- Press '2' to test socket creation and see resource impact
- Press '3' to check extra file descriptor count
Important Notes
Resource Management
- Each active socket (listening or connected) consumes system resources
- When the system runs out of buffers or sockets, it cannot accept incoming connections or make outgoing connections
- The listening socket test (option 2) temporarily uses port 10000 with a backlog of 5 connections
Network Initialization
- The application waits up to 10 seconds for an active network connection during startup
- System diagnostics are enabled by default (consider disabling for production builds)
Code Structure
main.cpp
UserMain() - Main application entry point
showMenu() - Display menu options
processCommand() - Handle user input
System Functions - Network resource monitoring
Development Notes
- System diagnostics are enabled for development purposes
- The code is designed for continuous operation with a command loop
- Error handling is implemented for socket operations