Python errno 模块,ENETRESET 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用errno.ENETRESET

项目:pipypd    作者:stressfm    | 项目源码 | 文件源码
def main():
    global HOST, PORT, EOF, MAXTRIES
    global s, tries, loops
    try:
        s.connect((HOST, PORT))
        while True:
            # Measure timing using GPIO4
            risetime = RCtime(4)
            # Send to the connected socket
            # (as we're using UDP, we must
            # send separate messages)
            s.sendall('foo %s%s' % (loops, EOF))
            s.sendall('bar %s%s' % (risetime, EOF))
            # Advance counter
            loops = loops + 1
    except socket.error as err:
        errcode = err[0]
        if errcode==errno.ECONNREFUSED:
            print 'Connection refused by host!'
        elif errcode==errno.ENETDOWN:
            print 'No network connection!'
        elif errcode==errno.ENETUNREACH:
            print 'Network unreachable!'
        elif errcode==errno.ENETRESET:
            print 'Network dropped connection!'
        elif errcode==errno.ECONNRESET:
            print 'Connection reset by peer!'
        elif errcode==errno.EHOSTDOWN:
            print 'Host is down!'
        elif errcode==errno.EHOSTUNREACH:
            print 'No route to host!'
        else:
            print 'Caught: %s!' % err

        if tries >= MAXTRIES:
            GPIO.cleanup()
            s.close()
            print 'No connection. Exiting.'
        else:
            print 'Tried %i of %i times.\nWaiting %is...' % (tries, MAXTRIES, tries/10)
            time.sleep(tries/10)
            tries = tries + 1
            main()
    except KeyboardInterrupt:
        GPIO.cleanup()
        s.close()
        print '%i loops' % loops