服务端代码
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, %sn' % 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'Clientn')
response = await client.receive()
print(response)
run(main)
https://github.com/agronholm/anyio
关于在 trio 或 asyncio 之上工作的高级异步并发和网络框架



