问题
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