How to get the client port in RequestHandler?

2019-08-14 14:47发布

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?

标签: tornado
2条回答
甜甜的少女心
2楼-- · 2019-08-14 15:04

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

查看更多
趁早两清
3楼-- · 2019-08-14 15:20

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.

查看更多
登录 后发表回答