TCP Client Example Application
Overview
This is a simple TCP client application built for NetBurner hardware that demonstrates how to create and use a TCP client connection. The application provides a web-based interface that allows users to send messages to any TCP server by specifying the destination IP address, port number, and message content.
Features
- Web-based Interface: Complete interaction through a web page interface
- Configurable Connection: Set destination IP address and port number
- Message Transmission: Send custom messages to TCP servers
- Auto-fill Functionality: Automatically fills in the requesting client's IP address as default destination
- Error Handling: Comprehensive error reporting and logging
- Real-time Feedback: Connection status and transmission results displayed
Application Structure
Core Files
- main.cpp: Main application entry point and initialization
- clientweb.cpp: Web interface implementation and TCP client functionality
- clientweb.h: Header file for web interface functions
Key Components
Main Application (main.cpp)
- Initializes the NetBurner system
- Enables system diagnostics
- Starts HTTP server for web interface
- Waits for active network connection
- Displays IP addresses
- Runs main application loop
Web Interface (clientweb.cpp)
- Implements web page form handling
- Processes POST variables from web form
- Manages TCP client connections
- Handles message transmission
- Provides real-time status feedback
How It Works
- Initialization: The application starts up, initializes the network, and launches the HTTP server
- Web Interface: Users access the web page which displays form fields for:
- Destination IP address (auto-filled with requesting client's IP)
- Destination port number (defaults to 2000)
- Message content
- Message Transmission: When the form is submitted:
- A TCP connection is established to the specified server
- The message is transmitted
- Connection status and results are logged
- The connection is closed
- Response: The web page redirects back to the main interface
Configuration
Default Settings
- Default Port: 2000
- Connection Timeout: 5 seconds
- Maximum Message Size: 1024 characters
Web Form Fields
tfDestIpAddr: Destination IP address field
tfDestPortNum: Destination port number field
tfMessage: Message content field
SendMessage: Submit button trigger
Usage Instructions
- Setup: Deploy the application to NetBurner hardware
- Network: Ensure the device is connected to your network
- Access: Open a web browser and navigate to the device's IP address
- Configure:
- Enter the destination TCP server IP address
- Set the destination port number
- Type your message
- Send: Click the submit button to transmit the message
- Monitor: Check the console output (MTTTY) for connection status and errors
Testing
TCP Server Requirement
A TCP server must be running and listening on the specified IP address and port before sending messages.
Included Test Server
NetBurner provides a Windows-based TCP server for testing:
- Location:
\nburn\pctools\TCP\TcpServerWin
- Includes: Executable and source code
- Purpose: Simple TCP server for testing client connections
Technical Details
Network Functions Used
Error Handling
- Connection failure detection and reporting
- Invalid parameter validation
- Timeout handling
- Detailed error logging to console
Memory Management
- Static buffers for message storage
- Automatic cleanup on connection close
- Bounds checking for message size
Troubleshooting
Common Issues
- Connection Failed: Ensure TCP server is running and accessible
- Network Not Ready: Wait for network initialization to complete
- Invalid IP Address: Verify IP address format and reachability
- Port Conflicts: Ensure destination port is not blocked or in use
Debug Output
All debug information is sent to stdout and can be viewed using MTTTY terminal application.