本文整理汇总了Python中nattraverso.portmapper.get_port_mapper函数的典型用法代码示例。如果您正苦于以下问题:Python get_port_mapper函数的具体用法?Python get_port_mapper怎么用?Python get_port_mapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_port_mapper函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: upnp_thread
def upnp_thread():
while True:
try:
is_lan, lan_ip = yield ipdiscover.get_local_ip()
if not is_lan:
continue
pm = yield portmapper.get_port_mapper()
yield pm._upnp.add_port_mapping(lan_ip, args.net.P2P_PORT, args.net.P2P_PORT, 'p2pool', 'TCP')
except:
if p2pool_init.DEBUG:
log.err()
yield deferral.sleep(random.expovariate(1/120))
开发者ID:gyver,项目名称:p2pool,代码行数:12,代码来源:main.py
示例2: upnp_thread
def upnp_thread():
while True:
try:
is_lan, lan_ip = yield ipdiscover.get_local_ip()
if is_lan:
pm = yield portmapper.get_port_mapper()
yield pm._upnp.add_port_mapping(lan_ip, args.p2pool_port, args.p2pool_port, 'p2pool', 'TCP')
except defer.TimeoutError:
pass
except:
if p2pool.DEBUG:
log.err(None, 'UPnP error:')
yield deferral.sleep(random.expovariate(1/120))
开发者ID:and-then,项目名称:p2pool-rav,代码行数:13,代码来源:main.py
示例3: remove_mapping
def remove_mapping(mapper, port):
print 'Removing mapping for port', port
return mapper.unmap(port).addCallback(on_mapping_removed, mapper).addErrback(error_occured)
def on_mapping_done(result, mapper, port):
print '\tNew mapping added for:', port
return mapper.get_port_mappings().addCallback(
got_mappings).addCallback(lambda x:remove_mapping(mapper, port)).addErrback(error_occured)
def add_mapping(mapper):
print 'Adding new mapping, faking an http server on port 10333 on this host'
from twisted.web import server, resource as web_resource
port = reactor.listenTCP(10333, server.Site(resource=web_resource.Resource()))
return mapper.map(port).addCallback(on_mapping_done, mapper, port).addErrback(error_occured)
def got_port_mapper(mapper):
print "\tGot port mapper:", mapper
print "Retreiving existing mappings"
return mapper.get_port_mappings().addCallback(
got_mappings).addCallback(lambda x:add_mapping(mapper)).addErrback(error_occured)
def error_occured(err):
print "\tError occured:", err
get_port_mapper().addCallbacks(got_port_mapper,error_occured).addCallback(lambda x:reactor.stop())
print 'Attempting to get_port_mapper()'
reactor.run()
开发者ID:jhargis,项目名称:nattraverso,代码行数:29,代码来源:portmapper.py
注:本文中的nattraverso.portmapper.get_port_mapper函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论