如何在RequestHandler中获取客户端端口? [英] How to get the client port in RequestHandler?

查看:31
本文介绍了如何在RequestHandler中获取客户端端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RequestHandler中我们可以使用self.request.remote_ip来获取客户端ip地址,但是如何获取客户端端口呢?

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

并且,如果客户端使用tornado.simple_httpclient.SimpleAsyncHTTPClient 实现,如何获取此连接的端口?

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 in open when self.request.connection.streamNone.示例输出:('127.0.0.1', 56209)

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

这篇关于如何在RequestHandler中获取客户端端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆