TCP Server Via Example
Overview
This application demonstrates a TCP server implementation for multi-interface NetBurner devices using the listenvia()
function. The server creates multiple listening sockets - one that listens on all network interfaces and additional sockets that listen on specific network interfaces.
Features
- Multi-Interface Support: Creates listening sockets for each available network interface
- Multiple Concurrent Connections: Supports up to 10 simultaneous TCP connections
- Port Management: Uses incrementing port numbers starting from port 23
- Single-Task Architecture: Uses
select()
to handle multiple sockets within one task
- Connection Monitoring: Provides detailed logging of connections and interface information
Technical Details
Configuration
- Base Port: 23 (Telnet)
- Maximum Connections: 10 concurrent connections
- Read Buffer Size: 1,024 bytes
- Connection Queue: Up to 5 pending connection requests per listening socket
Socket Architecture
The application creates the following listening sockets:
- One socket listening on all interfaces (port 23)
- For each available network interface:
- One socket on port 24 (listenPort + 1)
- One socket on port 24 + interface_number
Network Interface Handling
- Automatically detects available network interfaces using
GetInterfaceBlock()
- Creates dedicated listening sockets for each interface using
listenvia()
- Provides interface-specific connection information to clients
Usage
Building and Running
- Compile the application for your NetBurner device
- Deploy to the target hardware
- The application will automatically start listening on configured ports
Testing Connections
Use Telnet to test connections from the command line:
telnet <ip_address> <port>
Examples:
telnet 192.168.1.100 23
- Connect to the all-interfaces socket
telnet 192.168.1.100 24
- Connect to interface 1, port 24
telnet 192.168.1.100 25
- Connect to interface 1, port 25
Client Interaction
- Upon connection, clients receive a welcome message
- Interface information is displayed showing which interface accepted the connection
- Type 'Q' to quit and close the connection
- Server echoes received data and provides connection status
Code Structure
Main Components
Initialization**
Key Functions Used
Error Handling
- Connection Limit: When server is full, new connections are rejected with a message
- Socket Errors: Automatic detection and recovery of failed listening sockets
- Read Errors: Proper cleanup of corrupted client connections
- Interface Failures: Continues operation even if some interfaces fail
Application Output
The application provides detailed console output including:
- Network interface discovery and socket creation status
- Connection acceptance with client IP and port information
- Interface identification for each connection
- Data reception logging
- Connection closure notifications
- Error condition reporting
Requirements
- NetBurner hardware platform
- NetBurner SDK with TCP networking support
- Multi-interface network configuration (optional for full functionality)
Notes
- System diagnostics are enabled by default (should be disabled for production)
- Socket file descriptors are automatically managed and cleaned up
- The server continues running indefinitely until manually stopped