asynchronous joke
Project description
###Как использовать
-
Установка:
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for asyncio_tcp_messages_team_2-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 587264746c17211a68ebfe33c1126606e0449508411740458fd8238264f45353 |
|
MD5 | 08db3011d383ad2fba2a15e0621808a3 |
|
BLAKE2b-256 | 334ba9fe14ae72748a44f6c650c49d31a162b64e136e11f091fc59352643544e |