How to get the client port in RequestHandler?

☆樱花仙子☆ 提交于 2019-12-13 00:48:51

问题


In the RequestHandler we can use self.request.remote_ip to get the client ip address, but how to get the client port?

And, if the client side implemented with tornado.simple_httpclient.SimpleAsyncHTTPClient, how to get the port for this connection?


回答1:


Why do you want the client port? There's not currently a supported interface for this although I think self.request.connection.stream.socket.getpeername() will work (untested).

I don't understand your second question about "request port" in SimpleAsyncHTTPClient.




回答2:


try self.request.connection.context.address in open when self.request.connection.stream is None. Example output: ('127.0.0.1', 56209)



来源:https://stackoverflow.com/questions/33155831/how-to-get-the-client-port-in-requesthandler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!