This is a simple Python project that demonstrates socket communication between a server and a client. It includes a server implementation (server.py
), a daemonized server (daemon_server.py
), and a client (client.py
).
-
Navigate to the project directory:
cd your-sockets-project
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
In server.py, adjust the SERVER and PORT literals as needed:
# Update these values accordingly
SERVER = "localhost"
PORT = 8080
Run the basic server:
python server.py
Run the daemonized server:
python daemon_server.py
It will generate a temporary 'daemon_server.pid' file in the tmp folder containing a process ID value. Run the following command to stop the daemon:
kill $(cat tmp/daemon_server.pid)
The project includes a configuration file (config.ini) with the following settings:
[text_file] Section:
- linuxpath: The path to the text file used for searching string sent by client.
- reread_on_query: Whether to reread the file on each client query (True/False).
[ssl] Section:
- ssl_auth: Whether SSL authentication is enabled (True/False).
- certfile: The path to the SSL certificate file.
- keyfile: The path to the SSL key file.
In client.py, adjust the SERVER and PORT literals as needed:
# Update these values accordingly
SERVER = "localhost"
PORT = 8080
Run the client:
python client.py
This project uses pytest for testing. In test files contained in tests folder, adjust the SERVER and PORT literals as needed:
# Update these values accordingly
SERVER = "localhost"
PORT = 8080
Run the tests with the following command:
pytest
Run specific test files using:
pytest ./tests/{name of test file}
For the file search speed tests it is useful to add the -s flag:
pytest -s ./tests/{name of test file}
Type checking is performed using mypy. Run mypy with the following command:
mypy {name of file}
- pytest: Testing framework.
- mypy: Static type checker for Python.
- daemonize: Library for daemonizing processes.
Feel free to contribute to this project by opening issues or submitting pull requests.
This project is licensed under the MIT License.