This repository contains TCP-based client and server code for task processing.
- Python 3.10 and newer - pattern matching is used in both client and server.
Client:
$ python ./client.py --hlep
usage: client.py [-h] [-H HOST] [-P PORT] {task,status} ...
Send a task for processing or get its status.
positional arguments:
{task,status} task operations
task send a new task to server
status get task status
options:
-h, --help show this help message and exit
-H HOST, --host HOST server address
-P PORT, --port PORT server port
$ python ./client.py task --help
usage: client.py task [-h] [--packet] {1,2,3} task data
positional arguments:
{1,2,3} type of the task
task data content of the message
options:
-h, --help show this help message and exit
--packet run in packet mode
$ python ./client.py status --help
usage: client.py task [-h] [--packet] {1,2,3} task data
positional arguments:
{1,2,3} type of the task
task data content of the message
options:
-h, --help show this help message and exit
--packet run in packet mode
Server:
$ python .\server.py --help
usage: server.py [-h] [-H HOST] [-P PORT]
Start a task processing server.
options:
-h, --help show this help message and exit
-H HOST, --host HOST server address
-P PORT, --port PORT server port
-
Task is a unit of work, simulating a computation, that is run on the server. There are three types of tasks:
- Flip a string (
flip -> pilf
) with two seconds delay. - Swap even and odd characters in a string (
swap -> wspa, odd -> dod
) with five seconds delay. - Repeat each character in a string according to its position
(
repeat -> reepppeeeeaaaaatttttt
) with seven seconds delay.
- Flip a string (
-
Server does the following:
- Receives a task from the client.
- Adds the task to a queue to process one at a time.
- Responds to the client with an identifier of the task.
-
- Responds with task status (enqueued, processing, or done).
- Responds with a task result.
-
Client does the following:
- Sends task type and data to the server.
-
- Queries the server for task status.
- Queries the server for task result.
- Works in a packet mode, which can be interrupted:
- Sends task type and data to the server, displays identifier.
- Waits for task result (can display status).
- Displays task result.