Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 443
user3446151 Avatar asked Jan 27 '26 05:01

user3446151


1 Answers

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) 
like image 67
Gabriele Santomaggio Avatar answered Jan 29 '26 18:01

Gabriele Santomaggio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!