Search code examples
pythonpython-3.xwebsocketpython-asyncioaiohttp

aiohttp - how can I view the websocket msg buffer?


Unfortunately the documentation for this library is rather limited and I can find allusions to the websocket message buffer but no method to access it.

Does anyone know a way I can see the messages currently received by the connection but not yet passed to the 'async for msg in ws:' loop?

Namely the buffer used internally by the module to operate the inner loop in the following code:

async with session.ws_connect('wss://example.com') as ws:
    async for msg in ws:
        print(msg)

Solution

  • aiohttp has no Public API for accessing internal buffer for websocket messages. The only available way is async for msg in ws: or msg = await.receive().

    The internal buffer is an implementation detail, the code could be changed in future.