Как использовать
-
Установка:
pip install asyncio_tcp_messages_team_2
-
Пример сервера:
В начале объявляем класс MySocketLib с ip и портом. После чего регистрируем функции, которые вам нужны, для регистраций команды нужно указать декоратор @app.command (Если хотите получить адрес клиента, укажите первым аргументом addr с тайп хитом tuple пример def get_addr(addr: tuple))
import asyncio
from asyncio_tcp_messages_team_2.main import MySocketLib
app = MySocketLib('127.0.0.1', 8889)
ter = {}
@app.command async def set_data(key: str, val: int): await ter[key] = val
@app.command async def get_data(key: str): return ter[key]
asyncio.run(app.run())
-
Пример клиента:
import asyncio
async def tcp_client(): reader, writer = await asyncio.open_connection('127.0.0.1', 8889)
while True: message = input("Send: ") + "\n" if not message: break writer.write(message.encode()) await writer.drain() data = await reader.readline() print(data.decode()) print('Close the connection') writer.close()async def main(): await asyncio.gather(tcp_client())
if name == 'main': asyncio.run(main())
-
Пример работы:
set_data --key key val --val 21 12
ok get_data --key key --val 21 12
Metadata
Release files for asyncio-tcp-messages-team-2 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asyncio_tcp_messages_team_2-0.1.3.tar.gz | 4.2 kB | Without provenance | Details for asyncio_tcp_messages_team_2-0.1.3.tar.gz |
Release files / asyncio_tcp_messages_team_2-0.1.3.tar.gz
| Download URL | asyncio_tcp_messages_team_2-0.1.3.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bcb2a60192c4704787c4fb5ce5dfd2fef4ba2d6414e2cd4401facb44b99c5a3
|
|
BLAKE2b-256 checksum How to use checksums |
7000bb5fc58ded97c479b3b5536004cb983c9cbd9b2c9d613409bfbcec9d4b94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
|
Security for asyncio-tcp-messages-team-2 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.