Answer the question
In order to leave comments, you need to log in
How to implement receiving messages via websocket in python?
Hello. Tell me how to implement a connection to WS in python and receive all messages. Terminate the connection and return the result if 5 seconds have passed since the last server response.
This code only gets the first message and that's it
async def hello(uri):
async with websockets.connect(uri) as websocket:
await websocket.send('Привет')
await websocket.recv()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(hello(url))
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