Search code examples
python-3.xtornado

What is the recommended way to receive long messages using Tornado websockets?


I am running a web server using Tornado Python module on Windows 10. I was using on_message to handle incoming messages and it was working fine, until there was a need to send longer messages. It seems the connection gets forced closed at the end where the Tornado server is running. I don't see any error from the Tornado application though. However, I do see TCP resets coming from the socket running the Tornado app. I'd like to know instead of receiving long messages as one giant message what is the recommended way to receive such long messages. Code sample would be great.


Solution

  • Incoming websocket messages have a default limit of 10MiB. Tornado will not accept data over this limit.

    You can increase this limit by passing websocket_max_message_size to the Application:

    web.Application(
        # ...
        websocket_max_message_size=(20 * 1024 * 1024) # 20 MiB
    )