服務端代碼
from anyio import create_tcp_listener, run
#tcp服務端代碼,
async def handle(client):
async with client:
print("客戶端",client)
name = await client.receive(1024)
await client.send(b'Hello, %s\n' % name)
async def main():
listener = await create_tcp_listener(local_port=9999)
await listener.serve(handle)
run(main)
客戶端代碼
from anyio import connect_tcp, run
#tcp客戶端代碼
async def main():
async with await connect_tcp('127.0.0.1', 9999) as client:
await client.send(b'Client\n')
response = await client.receive()
print(response)
run(main)
https://github.com/agronholm/anyio
關于在 trio 或 asyncio 之上作業的高級異步并發和網路框架
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/357270.html
標籤:其他
上一篇:Nginx+Tomcat發布WebService soap:address location https 變為 http問題處理
