A simple client–server database application built using Python sockets.
The server listens for TCP connections, processes structured requests, and stores customer records in a text-based database.
This project was built as a learning exercise to explore TCP socket programming, basic protocol design, and server-side validation in Python.
- Python 3
socketsocketserver- Regular expressions (
re) - Threading (for controlled server shutdown)
python-socket-database/
├── server.py # TCP server implementation
├── client.py # Client-side menu interface
├── data.txt # Initial database file
├── data_out.txt # Updated database output
└── README.md
- Python 3.9+
- No external libraries required (standard library only)
- Open a terminal in the project root directory and run:
python server.pyYou should see:
Server is running... listening on localhost:9999- Open another terminal in the same directory and run:
python client.pyThis will display the interactive menu.
-
The client provides a menu-driven interface:
- Find Customer
- Add Customer
- Delete Customer
- Update Customer Age
- Update Customer Address
- Update Customer Phone
- Print Report
- Update File and Exit
-
Input is validated on both client and server sides
-
The server processes one request per connection
-
Data is stored in memory during runtime
- To save the database and shut down the server:
- Choose option 8 in the client
- The server writes data to data_out.txt
- The server shuts down gracefully
- After shutdown, the server must be restarted manually:
python server.pyValid phone numbers must follow this format:
<area-code>-<4 digits> -> xxx-1234
Allowed area codes:
- 394
- 426
- 901
- 514
Examples:
- 514-1234 (valid)
- 426-9876 (valid)
- 5141234 (invalid)
- 999-1234 (invalid)
- The server accepts one client connection at a time (intentional design)
- Requests are delimited using a newline (
\n) as the protocol terminator - Maximum request size is limited to prevent malformed input
- All communication uses TCP sockets
- TCP client–server architecture using Python sockets
- Menu-driven client interface
- Supports CRUD-style operations:
- Create (Add Customer)
- Read (Find Customer, Print Report)
- Update (Update Age, Address, Phone)
- Delete (Remove Customer)
- Custom text-based protocol using
|separators and\nas a message delimiter - Input validation on both client and server sides
- Case-insensitive customer name matching
- In-memory data storage with persistence to a text file on shutdown
- Graceful server shutdown triggered by client command
- Request size limits, timeout handling, and protection against malformed input
- Customer name and age are required fields, while address and phone number are optional
- The server is intentionally designed to handle one client session per run
- A simple text-based protocol is used for clarity and learning purposes
- Messages are delimited using a newline (
\n) to clearly define request boundaries - Customer names are treated as case-insensitive for usability
- Data is stored in memory during runtime and written to file only on shutdown
- A menu-driven client interface is used to simplify user interaction
- This project is not intended for production use
- Only one client should connect to the server at a time
- Data persistence relies on plain text files rather than a real database
- No authentication or encryption is implemented
- The server must be restarted manually after shutdown