Answer the question
In order to leave comments, you need to log in
How to implement an asynchronous client with two coroutines?
Hello!
There is no way to implement the following idea:
There are two coroutines
1. Waits for a message from the server and prints the response
async def handler(ws):
response = await ws.recv()
print(response)
async def ping(ws):
await asyncio.sleep(3)
await ws.send(b'ping')
async def main():
loop = asyncio.new_event_loop()
async with websockets.connect('ws://127.0.0.1:8080/ws') as ws:
await ws.send('hello'.encode())
while True:
await handler(ws)
await ping(ws)
asyncio.run(main())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question