Search code examples
pythonwebsockettornado

How do I get the client IP of a Tornado request from the WebSocket Handler?


http://stackoverflow.com/questions/3110919/how-do-i-get-the-client-ip-of-a-tornado-request

Above link tells us how we could derive the Client IP for a Request Handler. What about while using a Websocket Handler?

Thanks.


Solution

  • The class WebSocketHandler extends RequestHandler

    class WebSocketHandler(tornado.web.RequestHandler):
    

    So, you can get the ip in this way:

    class SocketHandler(tornado.websocket.WebSocketHandler):
        def open(self):
            logging.info('Client IP:' + self.request.remote_ip)