A networked database application that allows users to manage customer information through a client-server architecture. The server handles data validation, persistence, and business logic, while the client provides a user-friendly command-line interface.
- Customer Management: Add, find, update, and delete customer records
- Input Validation:
- Name: 1-10 characters
- Age: 1-120 years
- Address: Up to 20 characters
- Phone: Format
XXX-XXXX(area codes: 394, 426, 901, 514)
- Persistent Storage: Records saved to
data.txt - Error Handling: Comprehensive validation with detailed error messages
- Database Reports: Generate formatted reports of all customers
- Network Communication: TCP socket-based client-server model
├── server.py # Server implementation with database logic
├── client.py # Client with interactive menu interface
└── data.txt # Database file (auto-created)
- Python 3.6 or higher
- No external dependencies required (uses standard library only)
-
Clone or download the project files
# Ensure server.py and client.py are in the same directory -
Prepare the database file (optional)
- Create
data.txtin the same directory, or - Let the server create it automatically on first run
- Create
python server.pyThe server will:
- Load existing records from
data.txt - Display any skipped records with error messages
- Listen on
0.0.0.0:9999
python client.pyThe client will connect to 127.0.0.1:9999 and display the menu.
- Find Customer - Search for a customer by name
- Add Customer - Create a new customer record
- Delete Customer - Remove a customer from the database
- Update Customer Age - Modify age field
- Update Customer Address - Modify address field
- Update Customer Phone - Modify phone field
- Print Report - Display all customers sorted by name
- Exit - Close the connection
Database File (data.txt):
John|25|123 Main St|514-1234
Jane|30||426-5678
Fields are pipe-separated (|). Empty fields are allowed except for name and age.
| Field | Required | Format/Constraints |
|---|---|---|
| Name | Yes | 1-10 characters, unique (case-insensitive) |
| Age | Yes | Integer 1-120 |
| Address | No | Max 20 characters |
| Phone | No | XXX-XXXX where XXX ∈ {394, 426, 901, 514} |
The system provides specific error messages for:
- Invalid field formats
- Duplicate records
- Missing customers
- Database read errors
- Connection failures
Server settings (in server.py):
HOST = '0.0.0.0' # Listen on all interfaces
PORT = 9999 # Server port
DB_FILE = 'data.txt' # Database filenameClient settings (in client.py):
SERVER_IP = '127.0.0.1' # Server address
SERVER_PORT = 9999 # Server portPython DB Menu
1. Find customer
2. Add customer
...
Select: 2
Customer Name: Alice
Customer Age: 28
Customer Address: 456 Oak Ave
Customer Phone: 514-9999
Server response: Alice|28|456 Oak Ave|514-9999 added to database
- Protocol: TCP/IP with custom message format (
command::param1::param2...) - Encoding: UTF-8
- Buffer Size: 1024 bytes (client), 4096 bytes (server responses)
- Concurrency: Single-threaded, sequential client handling
- Data Structure: In-memory dictionary with case-insensitive keys
Connection Refused
- Ensure server is running before starting client
- Check firewall settings for port 9999
- Verify server IP/port configuration
Database Not Loading
- Check
data.txtexists in server directory - Verify file format (pipe-separated fields)
- Review server console for read errors
Najlaa Achouhal