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

13 views
Skip to first unread message

Tomforge

unread,
Jun 3, 2018, 8:10:16 AM6/3/18
to Autobahn
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()`?
Reply all
Reply to author
Forward
0 new messages