collector.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:n1mm_view 作者: n1kdo 项目源码 文件源码
def listener(db, cursor):
    """
    this is the UDP listener, the main loop.
    """
    s = socket(AF_INET, SOCK_DGRAM)
    s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
    s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    try:
        s.bind(('', config.N1MM_BROADCAST_PORT))
    except:
        logging.critical('Error connecting to the UDP stream.')
        return

    operators = Operators(db, cursor)
    stations = Stations(db, cursor)

    seen = set()
    run = True
    while run:
        try:
            udp_data = s.recv(BROADCAST_BUF_SIZE)
            process_message(db, cursor, operators, stations, udp_data, seen)

        except KeyboardInterrupt:
            logging.info('Keyboard interrupt, shutting down...')
            s.close()
            run = False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号