onClose(): How to distinguish between unestablished connections and opened connections?

#1

I am writing a websocket server in Autobahn Python with the Twisted framework. Currently I am doing something like this:
class MyProtocol(WebSocketServerProtocol):
def onOpen(self):
# Do some initialization

def onClose(self, wasClean, code, reason):
    # Do some cleanup

``

The problem is, denied/unable to be established websocket connections (which don’t trigger onOpen()) triggers onClose(). Is there an Autobahn/Twisted way for me to perform cleanup only for previously opened connections, ignoring unestablished connections? Can i determine this from the error code alone, or should i just set a self.wasOpen = True flag in my protocol’s onOpen()?

0 Likes