python - Can I get IP address and port of disconnected client in Tornado -


currently when tornado server receives 'connection opened' event, store client's websockethandler in players dict key being , ip/port combo.

players = {}  class wshandler(tornado.websocket.websockethandler):     def open(self):         global players         players[self.get_id()] = self      def get_id(self):         ip = self.request.remote_ip         port = str(self.stream.socket.getpeername()[1])         return ip + ":" + port 

what i'd remove player dict when connection closes. similar this:

class wshandler(tornado.websocket.websockethandler):     def on_close(self):         global players         players.pop(self.get_id(), none) 

the port doesn't seem accessible can't re-create id had set previously. possible retrieve port other way?

each connection create own instance of wshandler, store data on instance on initialisation:

def open(self):     self.id = self.get_id()     ... 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -