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?
try
self.request.connection.context.address
inopen
whenself.request.connection.stream
isNone
. Example output:('127.0.0.1', 56209)
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
.