Search code examples
pythonwebsockettornado

tornado websocket closing on server-side


I have a connection to websocket handler in my tornado app, and when i try to close it on server-side, i get unexpected event code which is not equal to one that i've specified in closing parameters

Handler's method code:

def on_message(self, message):
    # do some stuff
    self.close(code=200)

On client-side i expect onclose_event.code will be 200 but it appears to be 1006, is there a correct way to close websocket connection 'clearly' with specified code in tornado?

Tornado version i use is 4.1


Solution

  • Can you try Tornado 4.2? Handling of close codes changed in that version, although I'm not sure if it will fix this problem or not.

    From the 4.2 release notes: "When the other side closes a connection, we now echo the received close code back instead of sending an empty close frame."