本文整理汇总了Python中host.Host.port方法的典型用法代码示例。如果您正苦于以下问题:Python Host.port方法的具体用法?Python Host.port怎么用?Python Host.port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.Host
的用法示例。
在下文中一共展示了Host.port方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import port [as 别名]
def check():
global newcenter, nthreads
showthreads()
while workqueue and nthreads < MAXTHREADS:
(src, host, port) = workqueue.pop(0)
conn = gnut.ThrConn(host, port)
try:
conn.setDaemon(1)
conn.start()
except:
# print 'threading error', sys.exc_info()
workqueue.insert(0, (src, host, port))
# print 'think', nthreads
# nthreads = len(threading.enumerate()) - 1
# print 'actual', nthreads
# print 'threads:', threading.enumerate()
break
# nthreads = nthreads + 1
src.attempttime = time.time()
src.init(conn)
# print 'spawn', src
canvas.update()
for host in hosts.values():
if host.state in (Host.DROPPED, Host.REFUSED): continue
if newcenter: break
if host.conn and host.conn.messages:
for msg in host.conn.messages:
if isinstance(msg, gnut.Query) and msg.key == TESTKEY:
host.flash('red')
canvas.itemconfig(info, text=
'query echo from %s' % host.addr)
canvas.tkraise(info)
if host.conn.isAlive():
messages = host.conn.get(1)
else:
messages = filter(lambda msg: isinstance(msg, gnut.Pong),
host.conn.get())[:10]
host.conn.messages = []
if messages:
for msg in messages:
if isinstance(msg, gnut.Pong):
host.count('pong')
if msg.addr in ['127.0.0.1', '0.0.0.0']: continue
src = hosts.get(msg.addr)
if src:
src.resize(msg.files)
src.join(host)
else:
src = Host(canvas, msg.addr, msg.files, host)
src.kb = msg.kb
src.port = msg.port
top.arrange()
hosts[msg.addr] = src
workqueue.append((src, msg.addr, msg.port))
elif isinstance(msg, gnut.Query):
host.count('query')
if msg.key == TESTKEY:
host.flash('red')
canvas.itemconfig(info, text=
'query echo from %s' % host.addr)
canvas.tkraise(info)
host.gotquery(msg.key)
if msg.key and 32 <= ord(msg.key[0]) < 127:
key = string.join(string.split(msg.key, '\x00'), '')
querylist.append(key)
text = string.join(querylist[-60:], '\n')
canvas.itemconfig(queries, text=text)
else:
host.count('other')
canvas.update()
time.sleep(TF * 0.05)
if host.state == Host.CONNECTING:
if host.conn.connected:
nthreads = nthreads + 1
showthreads()
host.connecttime = time.time()
host.connect()
try: host.conn.ping(ttl=2)
except IOError: pass
if host.conn and not host.conn.isAlive() and not host.conn.messages:
# print 'terminated', host
if host.state == Host.CONNECTED:
host.drop()
elif host.conn.error:
errmsg = string.lower(host.conn.error[1].args[-1])
if host.state == Host.CONNECTING:
if string.find(errmsg, 'refused') >= 0:
host.refuse()
else:
host.delete()
del hosts[host.conn.host]
nthreads = nthreads - 1
if nthreads > MAXTHREADS - 5:
#.........这里部分代码省略.........
示例2: Host
# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import port [as 别名]
timestep = 100
win = Tkinter.Tk()
win.title('Gnutella')
win.wm_geometry('+0+0')
canvas = Tkinter.Canvas(win, width=600, height=600, bg='white')
canvas.pack()
event = threading.Event()
#addr = socket.gethostbyname('gnutellahosts.com')
addr = socket.gethostbyname('50.11.240.185')
top = Host(canvas, addr, 0)
top.kb = 0
#top.port = 6346
top.port = 49722
hosts = {addr: top}
workqueue = []
status = canvas.create_text(10, 0, font=('helvetica', 10),
anchor='nw', fill='white')
info = canvas.create_text(300, 599, font=('helvetica', 16),
anchor='s', justify='center')
queries = canvas.create_text(5, 599, font=('helvetica', 12),
anchor='sw', fill='grey')
canvas.lower(queries)
querylist = ['']
circles = []
fading = ['#ffd0d0', '#ffd8d8', '#ffe0e0', '#ffe8e8', '#fff0f0', '#fff8f8']
for r in range(10):