An async server realization using asyncio
in python.
- server.py: High-performance async server codes.
- client.py: High-performance async client codes.
- package.py: Define the format of different packages and ways to parse them.
- actions.py: Main logic of actions to process after recieved packages.
- protocol.py: Define how to frame a package.
- utils.py: Common utils defines here.
Adding a new action in pyasync_server
could be no more easier with folloing steps:
-
Define a function in
actions.py
.The arguments reveal data you need when executing the action. Pay attention to them is quite useful when defining the package structure later.
-
Add new package type in
package.py
.package
is the minimum unit where data is stored of each request. To define a new package type, you should:-
Add new enumeration to the class
PACKAGE
. -
Define functions to pack your new packages.
For example,
MARIADB_TEST
andANSWER_MARIADB_TEST
.
-
-
Add a new flow in
unpack_and_process()
inactions.py
TLS is disabled by default. To enable it, follow the instructions below:
Use this command to generate keys and certification annually:
openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt -batch
- -x509: to generate self-signed certification
- -days: period of validity
- -nodes: don't encrypt the private key
- -batch: use default of configured settings instead of getting them interactively
Make sure your client and server use the same server.crt
.
DO NOT DISTRIBUTE YOUR server.key
!!!
At last, modify enable_tls
to True
in config.py
.
Now your connections are under the protection of TLS.
Database is disabled by default. To enable it, follow the instructions below:
Edit requirements.txt
to enable modules related to database you need and install them with:
pip install -r requirements.txt
Edit server_config.py
to set parameters for connecting the database.
Finally, use connect()
to visit your database and do what you want.
- Compression threshold
- Compression benchmark