Пример #1
0
def echo_server(address, authkey):
    serv = Listener(address, authkey=authkey)
    while True:
        try:
            client = serv.accept()
            echo_client(client)
        except Exception:
            traceback.print_exc()
Пример #2
0
def rpc_server(handler, address, authkey):
    socket = Listener(address, authkey=authkey)
    while True:
        client = socket.accept()
        # handle_connection(client)
        t = Thread(target=handler.handle_connection, args=(client, ))
        t.daemon = True
        t.start()
Пример #3
0
def start(pipe):
    global conn
    listener = Listener('\\\\.\\pipe\\' + pipe, backlog=0)

    while True:
        conn = listener.accept()
        print("Connected to Binary Ninja")
        event_loop(conn)
Пример #4
0
 def __init__(self, dat, host = 'localhost', port=56002):
     threading.Thread.__init__(self)
     self.daemon = True
     self.gt = None
     self.dat = dat
     # Create a listener
     self.address = (host, port)
     self.listener = Listener(self.address)
Пример #5
0
def rpc_server(handler, addr, authkey):
    sock = Listener(addr, authkey=authkey)
    while True:
        client = sock.accept()
        t = Thread(target=handler.handle_connection,
                   args=(client, ),
                   daemon=True)
        t.start()
 def createSocket(self):
     '''Create socket and wait for a new client'''
     print 'Waiting for client'
     self.listener = Listener((self.address, self.port),
                              authkey=self.authkey)
     self.remote_conn = self.listener.accept()
     print 'Got client ' + self.listener.last_accepted[0] + ':%d' % (
         self.listener.last_accepted[1])
Пример #7
0
 def OnShow(self):
     ser = Listener(r'\\.\pipe\pipename')
     while True:
         conn = ser.accept()
         buff = conn.recv()
         if buff == '1':
             self.frame.OnShowConfig(1)
             conn.close()
Пример #8
0
 def listen(self):
     listener = Listener(self.address, authkey=b'secret password')
     conn = listener.accept()
     print('connection accepted from', listener.last_accepted)
     msg = conn.recv()
     conn.close()
     listener.close()
     return msg
def server():
    address = ('localhost', 6000)  # family is deduced to be 'AF_INET'
    with Listener(address, authkey=b'secret password') as listener:
        with listener.accept() as conn:
            print('connection accepted from', listener.last_accepted)
            conn.send([2.25, None, 'junk', float])
            conn.send_bytes(b'hello')
            conn.send_bytes(array('i', [42, 1729]))
Пример #10
0
 def __init__(self,
              address: str = "0.0.0.0",
              port: int = 6000,
              authkey=b'defaultkey'):
     self.address = address
     self.port = port
     self.__key = authkey
     self.listener = Listener((self.address, self.port), authkey=self.__key)
Пример #11
0
    def __init__(self, logger, endpoint=('localhost', 6000), authkey=None):
        self.logger = logger

        self.listener = Listener(endpoint, authkey=authkey)
        self.port = endpoint[1]

        self.sender_queue = Queue()
        self.receiver_queue = Queue()
Пример #12
0
    def run(self):
        '''
        listed on speficied port and 
        '''

        logger.debug('%s: waiting for connection at %s' %
                     (self.name, self.address))
        worker_conn = Listener(self.address)
        worker = worker_conn.accept()
        logger.debug('%s: connected to worker' % (self.name))

        # while the data queue is not empty
        while not self.d.empty():
            # send
            tic = time.time()
            x = self.d.get()
            toc = time.time() - tic
            logger.debug('%s: got another item' % (self.name, ))
            logger.debug('%s: elapsed time %f\n' % (
                self.name,
                toc,
            ))

            tic = time.time()
            worker.send(x)
            toc = time.time() - tic
            logger.debug('%s: sent data to worker' % (self.name, ))
            logger.debug('%s: elapsed time %f\n' % (
                self.name,
                toc,
            ))

            logger.debug('%s: waiting for result' % (self.name, ))
            tic = time.time()
            z = worker.recv()
            toc = time.time() - tic
            logger.debug('%s: got %s' % (self.name, str(z)))
            logger.debug('%s: elapsed time %f\n' % (
                self.name,
                toc,
            ))
            # try:
            #     z = worker.recv()
            # except (EOFError, ConnectionResetError):
            #     # something went wrong with this thread, put x back in the queue and terminate
            #     # other workers will deal with x, however order will not be correct
            #     logger.debug('%s: worker w%d failed' % (self.name,wid))
            #     logger.debug('%s: putting data back in the queue' % (self.name,))
            #     d.put(x)
            #     d.task_done()
            #     break

            tic = time.time()
            self.r.put(z)
            self.d.task_done()
            toc = time.time() - tic
            logger.debug('%s: put result in the queue' % (self.name, ))
            logger.debug('%s: elapsed time %f\n' % (self.name, toc))
Пример #13
0
def main(args=sys.argv):
    gui_debug = None
    if args[0] == '__CALIBRE_GUI_DEBUG__':
        gui_debug = args[1]
        args = ['calibre']

    try:
        app, opts, args = init_qt(args)
    except AbortInit:
        return 1
    from calibre.utils.lock import singleinstance
    from multiprocessing.connection import Listener
    si = singleinstance('calibre GUI')
    if si and opts.shutdown_running_calibre:
        return 0
    if si:
        try:
            listener = Listener(address=gui_socket_address())
        except socket.error:
            if iswindows:
                cant_start()
            if os.path.exists(gui_socket_address()):
                os.remove(gui_socket_address())
            try:
                listener = Listener(address=gui_socket_address())
            except socket.error:
                cant_start()
            else:
                return run_gui(opts, args, listener, app, gui_debug=gui_debug)
        else:
            return run_gui(opts, args, listener, app, gui_debug=gui_debug)
    otherinstance = False
    try:
        listener = Listener(address=gui_socket_address())
    except socket.error:  # Good si is correct (on UNIX)
        otherinstance = True
    else:
        # On windows only singleinstance can be trusted
        otherinstance = True if iswindows else False
    if not otherinstance and not opts.shutdown_running_calibre:
        return run_gui(opts, args, listener, app, gui_debug=gui_debug)

    communicate(opts, args)

    return 0
def doorTriggerLoop():
    address = (cfg.NETWORK_IP, int(cfg.NETWORK_PORT))
    listener = Listener(address)	    

    while True:
        # Receive incomming communications and set defaults
	conn = listener.accept()
	received_raw = ''
	received_raw = conn.recv_bytes()

	received = received_raw.lower()
	response = 'unknown command'
	trigger = False

        if received == 'trigger':
            trigger = True
            if state == 'open':
                response = 'closing'
            else:
                response = 'opening'
        elif received == 'open' or received == 'up':
            if state == 'open':
                response = 'already open'
            else:
                response = 'opening'
                trigger = True
        elif received == 'close' or received == 'down':
            if state == 'open':
                response = 'closing'
                trigger = True
            else:
                response = 'already closed'
	elif received == 'home' or received == 'set to home':
	    cfg.HOMEAWAY = 'home'
	    response = 'set to home'
        elif received == 'away' or received == 'set to away':
            cfg.HOMEAWAY = 'away'
            response = 'set to away'
        elif received == 'state' or received == 'status':
            response = get_garage_door_state() + ' and ' + cfg.HOMEAWAY
	elif received.startswith('firebase:'):
	    cfg.FIREBASE_ID = received_raw.replace('firebase:','')
            response = 'ok'

        conn.send_bytes(response)
	print 'received ' + received_raw + '. ' + response

        if trigger:
            GPIO.output(26, GPIO.LOW)
	    time.sleep(2)
	    GPIO.output(26, GPIO.HIGH)

        trigger = False
        time.sleep(1)

    conn.close()
    listener.close()
Пример #15
0
def server_status():
    while True:
        try:
            serv = Listener((CONF.STATUS_DOMAIN, CONF.STATUS_PORT),
                            authkey=b'CSDN-Data')
            client_conn = serv.accept()
            handler_status(client_conn)
        except Exception:
            traceback.print_exc()
Пример #16
0
 def init_communication(self):
     print "[IPC-S] Opening Server socket ... ",
     address = ('localhost', 6000)     # family is deduced to be 'AF_INET'
     self.listener = Listener(address)
     print "done!"
 
     print "[IPC-S] Waiting Client ... ",
     self.conn = self.listener.accept()
     print 'connection accepted from', self.listener.last_accepted
Пример #17
0
    def set_announcement_handler(self):
        '''Start the listener socket for BGP Announcements'''

        logger.info("Starting the announcement handler...")

        self.listener_eh = Listener(self.ah_socket, authkey=None)
        ps_thread = Thread(target=self.start_ah)
        ps_thread.daemon = True
        ps_thread.start()
Пример #18
0
def server_handler(address, authkey):
    serv = Listener(address, authkey=authkey)
    while True:  # server act like daemon
        try:
            client_conn = serv.accept()

            handler_client(client_conn)
        except Exception:
            import traceback; traceback.print_exc()
Пример #19
0
 def run(self):
     self.logger.info("Running.")
     with Listener(address=self.address, authkey=AUTHKEY) as listener:
         while True:
             self.logger.info("Listening for incoming connection...")
             with listener.accept() as con:
                 client = listener.last_accepted
                 self.logger.info("Connection accepted from %s.", client)
                 self._receive(con, client)
Пример #20
0
def mother(address):
    serv = Listener(address)
    while True:
        try:
            client = serv.accept()
            child(client)
        except EOFError:
            print('lol')
            pass
Пример #21
0
def place_order_service():
    print('place_order service begin...')
    while True:
        with Listener(address, authkey=b'secret password') as listener:
            with listener.accept() as conn:
                #print('connection accepted from', listener.last_accepted)
                ins_dict = conn.recv()
                #print(ins_dict)
                place_order(ins_dict)
Пример #22
0
def doorTriggerLoop():

    for door in cfg.GARAGE_DOORS:
        state = get_garage_door_state(door['pin'])
        status = cfg.HOMEAWAY

    address = (cfg.NETWORK_IP, int(cfg.NETWORK_PORT))
    listener = Listener(address, authkey='secret password')

    while True:
        conn = listener.accept()
        # print 'connection accepted from', listener.last_accepted

        received = conn.recv_bytes()
        response = 'unknown command'
        trigger = False

        if received == 'trigger':
            trigger = True
            if state == 'open':
                response = 'closing garage door'
            else:
                response = 'opening garage door'
        elif received == 'open':
            if state == 'open':
                response = 'garage door already open'
            else:
                response = 'opening garage door'
                trigger = True
        elif received == 'close':
            if state == 'open':
                response = 'closing garage door'
                trigger = True
            else:
                response = 'garage door alredy closed'
        elif received == 'state':
            response = 'the garage door is' + state
        elif received == 'home':
            cfg.HOMEAWAY = 'home'
            response = 'alert status set to HOME'
        elif received == 'away':
            cfg.HOMEAWAY = 'away'
            response = 'alert status set to AWAY'

        conn.send_bytes(response)
        print 'Received command to ' + received + ' the garage door. Response was ' + response

        if trigger:
#            GPIO.setup('7', GPIO.OUT)
            print 'Door triggered'

#        GPIO.setup('7', GPIO.IN)
        trigger = False
        time.sleep(1)

    conn.close()
    listener.close()
Пример #23
0
 def listen(self):
     with Listener((self.address, self.port+self.id)) as listener:
         while True:
             with listener.accept() as conn:
                 data = conn.recv()
                 with self.clock_lock:
                     self.clock = max(data['clock'], self.clock) + 1
                 print(f"{self.clock} {data['content']}")
                 conn.close()
Пример #24
0
def file_service():
    print('beging filer')
    while True:
        with Listener(address, authkey=b'secret password') as listener:
            with listener.accept() as conn:
                # print('connection accepted from', listener.last_accepted)
                ins_dict = conn.recv()
                #print(ins_dict)
                conn.send(deal_file(ins_dict))
Пример #25
0
def server():
    work_serv = Listener('\0singe', authkey=b'peekaboo')
    worker = work_serv.accept()
    print('Got a worker')
    worker_pid = worker.recv()
    print(worker_pid)

    client = os.open("/", os.O_RDONLY)
    send_handle(worker, client, worker_pid)
Пример #26
0
    def listenerThread(self):
        # clean if previous run crashes
        tryRemove(constants.FRONTEND_SOCKET[0])

        with Listener(*constants.FRONTEND_SOCKET) as listener:
            while True:
                with listener.accept() as conn:
                    payload = conn.recv()
                    self.agent.createTasksAction(payload)
Пример #27
0
def SendAndWaitForResponse(request: dict) -> bool or dict:
    with Client(client) as connection:
        connection.send(request)
    with Listener(server) as listener:
        with listener.accept() as connection:
            try:
                return connection.recv()
            except EOFError:
                return False
Пример #28
0
def echo_server(address, authkey):
    serv = Listener(address, authkey=authkey)
    while True:
        try:
            client = serv.accept()
            Thread(target=echo_client, args=(client, )).start()
            # echo_client(client)
        except Exception:
            traceback.print_exc()
Пример #29
0
def client_listener():
    cl = Listener(address=local_listener[0], authkey=local_listener[1])
    print '.............client listener starting'
    print '.............accepting conexions'
    while True:
        conn = cl.accept()
        print '.............connection accepted from', cl.last_accepted
        m = conn.recv()
        print '.............message received from server', m
Пример #30
0
 def _listenThread(self):
     address = ('localhost', self.port)  # family is deduced to be 'AF_INET'
     listener = Listener(address, authkey=self.pwd)
     while True:
         conn = listener.accept()
         self._printDebug('MultiBus,Listner: connection accepted from' +
                          str(listener.last_accepted))
         p = Process(target=self._connThread, args=(conn, ))
         p.start()