当前位置: 首页>>代码示例>>Python>>正文


Python Host.kb方法代码示例

本文整理汇总了Python中host.Host.kb方法的典型用法代码示例。如果您正苦于以下问题:Python Host.kb方法的具体用法?Python Host.kb怎么用?Python Host.kb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在host.Host的用法示例。


在下文中一共展示了Host.kb方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check

# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import kb [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:
#.........这里部分代码省略.........
开发者ID:Gnumaru,项目名称:gnuTellaVision2,代码行数:103,代码来源:gtv.py

示例2: Host

# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import kb [as 别名]
MAXTHREADS = 20
nthreads = 0
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 = []
开发者ID:Gnumaru,项目名称:gnuTellaVision2,代码行数:33,代码来源:gtv.py


注:本文中的host.Host.kb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。