真是费了我九牛二虎之力,终于搞定
网上有说如下方式获取的
class
CustomTProcessor(TProcessor):
def
process_in(
self
, iprot):
api, type, seqid = iprot.read_message_begin()
if
api
not in
self
._service.thrift_services:
iprot.skip(TType.STRUCT)
iprot.read_message_end()
return
api, seqid, TApplicationException(TApplicationException.UNKNOWN_METHOD),
None
# noqa
args =
getattr
(
self
._service, api +
"_args"
)()
args.read(iprot)
iprot.read_message_end()
result =
getattr
(
self
._service, api +
"_result"
)()
# convert kwargs to args
api_args = [args.thrift_spec[k][
1
]
for
k
in
sorted
(args.thrift_spec)]
# get client IP address
client_ip, client_port = iprot.trans.sock.getpeername()
def
call
():
f = <

本文记录了在Thrift服务器端如何通过Python获取客户端IP地址的过程,详细介绍了通过调试和理解TCP连接原理找到获取客户端IP的方法,并给出了修改Thrift Server和Processor的实现方案。
最低0.47元/天 解锁文章
408





