A robust Python client-server application with enhanced error handling, logging, and structured code organization.
PhantomStrike/
├── Server.py # Enhanced server script
├── server_config.ini # Server configuration
├── test_server.py # Server unit tests
├── client/ # Client package
│ ├── __init__.py
│ ├── client_config.ini # Client configuration
│ ├── requirements.txt # Client dependencies
│ ├── core/ # Core client functionality
│ │ ├── __init__.py
│ │ └── client_main.py # Main client application
│ ├── functions/ # Utility functions
│ │ ├── __init__.py
│ │ └── data_sender.py # Data transmission module
│ └── tests/ # Unit tests
│ ├── __init__.py
│ ├── test_client_main.py
│ └── test_data_sender.py
└── README.md # This file
- Multi-threaded: Handles multiple client connections simultaneously
- Robust Error Handling: Graceful handling of connection errors and exceptions
- Comprehensive Logging: Detailed logging to both file and console
- Configuration Management: External configuration file support
- Graceful Shutdown: Proper cleanup on server termination
- Client Acknowledgment: Sends confirmation messages to clients
- Modular Design: Organized into core and utility modules
- System Information Collection: Gathers and sends system details
- Interactive Mode: Manual data entry and command interface
- Automated Mode: Predefined sequence of operations
- Retry Logic: Automatic retry on connection failures
- Comprehensive Logging: Detailed operation logging
- Python 3.7+ (tested with Python 3.9+)
- No external dependencies required - uses only Python standard library
-
Download/Clone the project
git clone <repository-url> cd PhantomStrike
-
Verify Python installation
python --version # Should show Python 3.7 or higher -
No additional installation required - ready to use!
-
Navigate to client directory
cd client -
Configure client (optional)
- Edit
client_config.inito change server settings - Default settings work for local testing
- Edit
-
Run client
# Automated mode (default) python core/client_main.py # Interactive mode python core/client_main.py interactive
-
Configure server (optional)
- Edit
server_config.inito change port/host settings - Default settings work for local testing
- Edit
-
Run server
python Server.py
-
Install PyInstaller
pip install pyinstaller
-
Compile Server
pyinstaller --onefile --name PhantomStrike-Server Server.py
-
Compile Client
cd client pyinstaller --onefile --name PhantomStrike-Client core/client_main.py -
Compiled executables will be in
dist/folder
-
Install cx_Freeze
pip install cx_Freeze
-
Create setup script for server
# setup_server.py from cx_Freeze import setup, Executable setup( name="PhantomStrike-Server", version="1.0.0", executables=[Executable("Server.py")] )
-
Create setup script for client
# setup_client.py from cx_Freeze import setup, Executable setup( name="PhantomStrike-Client", version="1.0.0", executables=[Executable("client/core/client_main.py")] )
-
Compile
python setup_server.py build python setup_client.py build
-
Create Dockerfile for server
FROM python:3.9-slim WORKDIR /app COPY . . EXPOSE 12345 CMD ["python", "Server.py"]
-
Create Dockerfile for client
FROM python:3.9-slim WORKDIR /app COPY client/ . CMD ["python", "core/client_main.py"]
-
Build and run
docker build -t phantomstrike-server . docker build -t phantomstrike-client -f client/Dockerfile .
- Download Python from python.org
- Install Python with "Add to PATH" option checked
- Open Command Prompt or PowerShell
- Navigate to project folder
cd C:\path\to\PhantomStrike - Run applications
# Terminal 1 - Server python Server.py # Terminal 2 - Client cd client python core\client_main.py
-
Install Python (if not already installed)
# Ubuntu/Debian sudo apt update && sudo apt install python3 python3-pip # CentOS/RHEL sudo yum install python3 python3-pip # macOS (with Homebrew) brew install python3
-
Make scripts executable (optional)
chmod +x Server.py chmod +x client/core/client_main.py
-
Run applications
# Terminal 1 - Server python3 Server.py # Terminal 2 - Client cd client python3 core/client_main.py
-
"python not found" error
- Windows: Add Python to PATH or use
pyinstead ofpython - Linux/macOS: Use
python3instead ofpython
- Windows: Add Python to PATH or use
-
Permission denied errors
- Linux/macOS: Use
sudofor system-wide installation - Or install in user directory with
--userflag
- Linux/macOS: Use
-
Module not found errors
- Ensure you're in the correct directory
- Check Python version compatibility
-
Port already in use
- Change port in configuration files
- Kill existing process:
lsof -ti:12345 | xargs kill(Linux/macOS)
[SERVER]
HOST = 0.0.0.0
PORT = 12345
MAX_CONNECTIONS = 5
BUFFER_SIZE = 1024
[LOGGING]
LOG_LEVEL = INFO
LOG_FILE = server.log
CONSOLE_OUTPUT = true[CLIENT]
SERVER_HOST = 127.0.0.1
SERVER_PORT = 12345
CONNECTION_TIMEOUT = 10
RETRY_ATTEMPTS = 3
[LOGGING]
LOG_LEVEL = INFO
LOG_FILE = client.log
CONSOLE_OUTPUT = truepython Server.pyThe server will:
- Start listening on the configured host and port
- Log all activities to
server.logand console - Handle multiple client connections
- Send acknowledgment messages to clients
cd client
python core/client_main.pycd client
python core/client_main.py interactiveinfo- Send system information to serverquit- Exit the client- Any other text - Send as message to server
The client automatically collects and sends:
- Operating system details
- Platform information
- Python version
- Hardware information
- Timestamp
- Connection retry with exponential backoff
- Graceful handling of network errors
- Comprehensive error logging
python test_server.pycd client
python -m unittest tests.test_client_main
python -m unittest tests.test_data_senderpython test_server.py
cd client
python -m unittest discover tests- File:
server.log - Console: Enabled by default
- Format:
YYYY-MM-DD HH:MM:SS - LEVEL - MESSAGE
- File:
client/client.log - Console: Enabled by default
- Format:
YYYY-MM-DD HH:MM:SS - LEVEL - MESSAGE
- Socket errors during client handling
- Connection timeout handling
- Graceful shutdown on signals (SIGINT, SIGTERM)
- Proper resource cleanup
- Connection timeout and retry logic
- Network error recovery
- Configuration file error handling
- Graceful degradation on failures
- Server: Modify
Server.pyand add tests totest_server.py - Client Core: Modify
client/core/client_main.pyand add tests toclient/tests/test_client_main.py - Client Functions: Modify
client/functions/data_sender.pyand add tests toclient/tests/test_data_sender.py
- All functions and classes have docstrings
- Comprehensive error handling
- Unit tests for all public functions
- English comments and documentation
- Logging for all significant operations
-
Port Already in Use
- Change the port in configuration files
- Check if another instance is running
-
Connection Refused
- Ensure server is running
- Check host and port configuration
- Verify firewall settings
-
Permission Denied
- Run with appropriate permissions
- Check file system permissions
Enable debug logging by changing LOG_LEVEL = DEBUG in configuration files.
This project is provided as-is for educational and development purposes.