Esempio n. 1
0
File: srv.py Progetto: jponf/dremo
def setUpSockets():
    """setUpSockets() -> tcp_socket, multicast_socket

    Sets up the clients connection socket and the multicast socket.

    """
    opt = gdata.getCommandLineOptions()
    queue_size = opt.connection_queue_size
    iface = opt.ip

    mon_sock = None; cmd_sock = None; mgroup_sock = None

    # Bind conn_sock
    try:
        mon_sock = common.createServerTCPSocket(iface, opt.mon_port, queue_size)
        logging.info('Monitor socket bound to %s:%d' % (iface, opt.mon_port))

        cmd_sock = common.createServerTCPSocket(iface, opt.cmd_port, queue_size)
        logging.info('Client socket bound to %s:%d' % (iface, opt.cmd_port))

        # Set multicast socket options (only send)
        mgroup_sock = common.createMulticastSocket(None, opt.multicast_group_ttl)
        logging.info('Multicas socket created (Not joined)')
        
    except socket.error, e:
        logging.critical("%s [%s]. Closing sockets" % (str(e), opt.ip))
        if mon_sock: mon_sock.close()
        if cmd_sock: cmd_sock.close()
        sys.exit(-1)    
Esempio n. 2
0
def setUpSockets():
    """setUpSockets() -> tcp_socket, multicast_socket

    Sets up the clients connection socket and the multicast socket.

    """
    opt = gdata.getCommandLineOptions()
    queue_size = opt.connection_queue_size
    iface = opt.ip

    mon_sock = None
    cmd_sock = None
    mgroup_sock = None

    # Bind conn_sock
    try:
        mon_sock = common.createServerTCPSocket(iface, opt.mon_port,
                                                queue_size)
        logging.info('Monitor socket bound to %s:%d' % (iface, opt.mon_port))

        cmd_sock = common.createServerTCPSocket(iface, opt.cmd_port,
                                                queue_size)
        logging.info('Client socket bound to %s:%d' % (iface, opt.cmd_port))

        # Set multicast socket options (only send)
        mgroup_sock = common.createMulticastSocket(None,
                                                   opt.multicast_group_ttl)
        logging.info('Multicas socket created (Not joined)')

    except socket.error, e:
        logging.critical("%s [%s]. Closing sockets" % (str(e), opt.ip))
        if mon_sock: mon_sock.close()
        if cmd_sock: cmd_sock.close()
        sys.exit(-1)
Esempio n. 3
0
File: cli.py Progetto: jponf/dremo
def main():
    setUpLogger()
    printCommandLineOptions()

    # SysInfo data
    sinfo = common.SysInfo()
    sinfo.update()
    awakener = threading.Event()

    # Sockets to listen to
    mcsock = None
    listen_sock = None

    opt = gdata.getCommandLineOptions()

    try:
        client_id, multicast_group, multicast_port = beginConnection(
                                                    opt.broker_host, 
                                                    opt.broker_port,
                                                    opt.listen_port,
                                                    sinfo,
                                                    opt.connection_timeout)

        # Start multicast socket
        mcsock = common.createMulticastSocket(multicast_port)
        common.joinMulticastGroup(mcsock, multicast_group)

        # Begin auto-updating
        auto_update = AutoUpdater(opt.time_between_updates, opt.broker_host, 
                                opt.broker_port, client_id, sinfo, awakener, 
                                opt.connection_timeout, opt.update_max_tries)
        auto_update.daemon = True
        auto_update.start()

        # Create socket to listen to incoming connections
        sock = common.createServerTCPSocket('0.0.0.0', opt.listen_port,
                                            opt.connection_queue_size)
        
        # Listen for incoming connections
        _acceptForever(sock, mcsock, awakener, sinfo, client_id,
                    opt.connection_timeout, opt.time_between_updates)

    except KeyboardInterrupt: 
        logging.info("Finishing due to KeyboardInterrput")
    except Exception, e:
        logging.critical("Finishing due to unknown exception:\n%s" % str(e))
        if opt.debug:
            import traceback; traceback.print_exc(sys.stderr)
Esempio n. 4
0
def main():
    setUpLogger()
    printCommandLineOptions()

    # SysInfo data
    sinfo = common.SysInfo()
    sinfo.update()
    awakener = threading.Event()

    # Sockets to listen to
    mcsock = None
    listen_sock = None

    opt = gdata.getCommandLineOptions()

    try:
        client_id, multicast_group, multicast_port = beginConnection(
            opt.broker_host, opt.broker_port, opt.listen_port, sinfo,
            opt.connection_timeout)

        # Start multicast socket
        mcsock = common.createMulticastSocket(multicast_port)
        common.joinMulticastGroup(mcsock, multicast_group)

        # Begin auto-updating
        auto_update = AutoUpdater(opt.time_between_updates, opt.broker_host,
                                  opt.broker_port, client_id, sinfo, awakener,
                                  opt.connection_timeout, opt.update_max_tries)
        auto_update.daemon = True
        auto_update.start()

        # Create socket to listen to incoming connections
        sock = common.createServerTCPSocket('0.0.0.0', opt.listen_port,
                                            opt.connection_queue_size)

        # Listen for incoming connections
        _acceptForever(sock, mcsock, awakener, sinfo, client_id,
                       opt.connection_timeout, opt.time_between_updates)

    except KeyboardInterrupt:
        logging.info("Finishing due to KeyboardInterrput")
    except Exception, e:
        logging.critical("Finishing due to unknown exception:\n%s" % str(e))
        if opt.debug:
            import traceback
            traceback.print_exc(sys.stderr)