M
M
mapleart22021-12-05 02:57:03
Python
mapleart2, 2021-12-05 02:57:03

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))


Please let me know how to get all messages.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question