Beispiel #1
0
    def run(self):
        print('external control')
        # Trying to remove the old socket file after a nasty stop
        try:
            os.remove(CONFIGURATION_NETWORK_INTERFACE_SERVER)
        except:
            pass
        if self._is_unix_addr(CONFIGURATION_NETWORK_INTERFACE_SERVER):
            self._main_socket = socket.socket(socket.AF_UNIX)
            self._main_socket.bind(CONFIGURATION_NETWORK_INTERFACE_SERVER)
        else:
            addr, port = CONFIGURATION_NETWORK_INTERFACE_SERVER.split(':')
            self._main_socket = socket.socket(socket.AF_INET)
            self._main_socket.bind((addr, int(port)))
        self._main_socket.listen(1)
        while not self._stop_server:
            try:
                self._answer_socket, addr = self._main_socket.accept()
                data = self._answer_socket.recv(1024)
                logging.info('recieived commande ||%s|| ', data)
                self._execute(data)# executing command

                self._speaking_event.wait() # waiting for the command to end
                self._speaking_event.clear()
            except Exception, e:
                logging.error('%s', e)
            finally:
Beispiel #2
0
 def halt_external_control(self):
     logging.warning('Halt external control asked')
     self._stop_server = True
     self._speaking_event.set()
     if self._main_socket != None:
         try:
             if self._is_unix_addr(CONFIGURATION_NETWORK_INTERFACE_SERVER):
                 s = socket.socket(socket.AF_UNIX)
                 s.connect(CONFIGURATION_NETWORK_INTERFACE_SERVER)
             else:
                 addr, port = CONFIGURATION_NETWORK_INTERFACE_SERVER.split(':')
                 s = socket.socket(socket.AF_INET)
                 s.connect(('127.0.0.1', int(port)))
             s.sendall('dummy')
             s.recv(1024)
             s.close()
         except Exception, e:
             logging.error('%s', str(e))
             logging.warning(traceback.format_exc())