TCP No Block Connect Test
Overview
This application demonstrates the difference between blocking and non-blocking TCP connections using NetBurner embedded networking hardware. The program provides an interactive menu system that allows users to test both standard blocking connect() calls and non-blocking NoBlockConnect() calls.
Purpose
The standard TCP connect call will block until the connection is either made or fails. The non-blocking connect call will initiate a TCP connection and return immediately, allowing the application to continue processing while the connection is established in the background.
Features
- Interactive menu-driven interface
- Support for both blocking and non-blocking TCP connections
- Real-time connection state monitoring
- Automatic periodic data transmission (every 5 seconds)
- User input forwarding over established connections
- Configurable destination IP address and port
Menu Options
The application provides the following commands:
- C - Make a connection using standard blocking
connect()
- N - Make a connection using non-blocking
NoBlockConnect()
- X - Close the current connection
- I - Specify the destination IP address and port number
- Any other character - Send the character over the TCP connection (if established)
How It Works
Blocking Connection (C command)
- Prompts for destination IP and port if not already set
- Calls
connect() which blocks until connection succeeds or fails
- Immediately reports success or failure
- Connection is ready for data transmission upon success
Non-Blocking Connection (N command)
- Prompts for destination IP and port if not already set
- Calls
NoBlockConnect() which returns immediately
- Reports "Connect started" if the call succeeds
- Continuously monitors connection state using
TcpGetSocketState()
- Reports "NoBlock connection is done" when
TCP_STATE_ESTABLISHED is reached
Automatic Features
- Sends a timestamp message every 5 seconds over established connections
- Displays current TCP state during non-blocking connection attempts
- Forwards any typed characters to the remote host when connected
Technical Details
Build Requirements
- NetBurner development environment
- NetBurner hardware platform
- Standard NetBurner libraries (tcp.h, utils.h, iosys.h, etc.)
Usage Example
- Run the application on NetBurner hardware
- When prompted, enter the destination IP address
- Enter the destination port number
- Use menu commands to test different connection methods:
- Try 'C' for blocking connection
- Try 'N' for non-blocking connection
- Use 'X' to close connections
- Use 'I' to change destination settings
- Type any characters to send data over established connections
Connection State Monitoring
For non-blocking connections, the application continuously displays the TCP state:
- State values correspond to standard TCP states
- Connection is ready when
TCP_STATE_ESTABLISHED is reached
- Failed connections will show appropriate error states
Notes
- Only one connection can be active at a time
- IP address and port cannot be changed while connected
- System diagnostics are enabled for debugging (should be disabled in production)
- The application runs in an infinite loop until manually terminated