TCP Navigator is a multithreaded TCP server application designed to handle concurrent client connections, search strings within a specified file, and return query results based on specified configurations. The server supports both static and dynamic file reads, SSL configuration, and real-time file querying based on client requests.
TCP Navigator is a multithreaded server application that binds to a specified port and listens for incoming client connections. It accepts client queries, searches for an exact match within a specified file, and returns either "STRING EXISTS" or "STRING NOT FOUND" as the response. The project includes configurable options for file reading behavior (REREAD_ON_QUERY), SSL encryption, and logging.
- Concurrent Connections: The server can handle unlimited concurrent connections using multithreading.
- Configurable File Reads:
REREAD_ON_QUERY: If set toTrue, the file is re-read for each client query. IfFalse, the file is loaded once at startup and stored in memory.
- Exact String Matching: The server searches for a complete line match of the client's query in the specified file.
- Configurable SSL/TLS Support: The server supports SSL encryption, with paths to SSL certificates specified in the configuration.
tcp_navigator/
├── config.ini # Configuration file for server settings
├── docs # Documentation files
├── src # Source code
│ ├── configuration.py # Configuration management
│ ├── constants.py # Constants and enumerations
│ ├── core
│ │ ├── client.py # TCP client implementation
│ │ ├── server.py # TCP server implementation
│ │ ├── helpers
│ │ │ ├── file_loader.py # File loader with search algorithms
│ │ │ ├── logging_helper.py # Logger setup helper
│ └── tests # Unit and performance tests
│ ├── test_client.py # Client tests
│ ├── test_server.py # Server tests
└── ssl # SSL certificates
├── cert.pem # SSL certificate
└── key.pem # SSL private key
The application’s behavior is controlled by a configuration file (config.ini), which contains essential settings such as the FILE_PATH, SSL configuration, and SERVER_CONFIG. The REREAD_ON_QUERY flag is located inside Configuration class to improve bool type precision.
-
config.ini:linuxpath(FILE_PATH): Path to the file where the server will search for query matches.host(SERVER_CONFIG): String containing the server's address.port(SERVER_CONFIG): Integer value of the server's port.cert_path(SSL): Path to the ssl certificate.key_path(SSL): Path to the ssl private key.
-
configuration.Configuration:REREAD_ON_QUERY: If set toTrue, the file is re-read for each query. If set toFalse, the file is loaded once on server startup.SSL_ENABLED: Enables or disables SSL.SSL_CERT_PATHandSSL_KEY_PATH: Paths to the SSL certificate and key files. Correspond toconfig.iniconfigurations.HOSTandPORT: Correspond to host and port configured in theconfig.ini
-
Unzip the Repository:
- Navigate to the
tcp_navigatordirectory if you are not already there:
cd tcp_navigator - Navigate to the
-
Set Up a Virtual Environment: Choose either Poetry or pip to set up a virtual environment.
- Ensure you have Poetry installed (you can install it from here).
- Create a virtual environment and install dependencies:
poetry install
- Activate the virtual environment:
poetry shell
-
Ensure you have Python 3.10+ installed, then create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate
- On macOS/Linux:
-
Install required libraries:
pip install -r requirements.txt
-
Set Up SSL (Optional): If using SSL, place your SSL certificate and key files in the paths specified in
config.ini:
[SSL]
cert_path=ssl/cert/cert.pem
key_path=ssl/key/key.pem- Edit Configuration File:
Update the
config.inifile as needed.
- Run tests:
pytest src/tests -v - Start the Server:
python -m src.core.server-
Send Client Queries: The server listens for incoming client queries on the specified port. Use a TCP client to connect and send queries.
-
Start the client
python -m src.core.client- **Alternatively, use
ncas a TCP Client **:
echo "query_string" | nc localhost <PORT>To benchmark multiple file-search algorithms and determine the most efficient for large files on Linux.
- Low-Level File Search (mmap + os): Direct memory-mapped access for optimized low-level reading.
- High-Level File Search (open + mmap): Higher-level file reading with memory-mapping.
- Brute-Force Line-by-Line Search: Sequentially reads each line.
- Regex-Based Search: Allows complex pattern matching.
- Linux
grepCommand: Highly optimized for text search.
| Algorithm | Rows (10K) | Rows (50K) | Rows (100K) | Rows (250K) | Rows (500K) | Rows (1M) |
|---|---|---|---|---|---|---|
| Grep (Linux) | 3.4 ms | 4.4 ms | 6.8 ms | 7.0 ms | 14.7 ms | 27.5 ms |
| Regex Search | 2.1 ms | 4.0 ms | 8.0 ms | 14.0 ms | 25.0 ms | 46.0 ms |
| Brute-Force Search | 5.8 ms | 15.7 ms | 27.6 ms | 47.6 ms | 100.5 ms | 269.8 ms |
- Best Overall Performance: The Linux
grepcommand. - Optimal Pattern Matching: Regex-based search for complex queries.
- Caching Impact: With
REREAD_ON_QUERYenabled, lookups average 0.02 ms due to constant-time hashmap access.
- Testing: Unit tests cover both server and client functionality, multithreading performance, and exception handling.
- TCP Logging: Captures client details, query text, and execution time for each request.
- SSL Support: Optional SSL enables secure client-server communication.
- Caching: For static data, enabling
REREAD_ON_QUERYsignificantly improves search speed by caching file content.