Exemple #1
0
class NetServer(Thread):

    def __init__(self, port=8080, logRequests=True):
        Thread.__init__(self)
        self.__port = port
        self.__logRequests = logRequests
        self.__server = None
        self.__running = False
        self.State = None
        self.start()
        while not self.__running:
            sleep(0)

    def stop(self):
        if self.State is not None:
            self.State.set_update_period(0)
        self.__server.shutdown()
        self.__server.server_close()
        self.join()

    def run(self):
        #register API
        self.State = NetServerState() # accessor for state object for tests and shutting down, etc
        self.__server = SimpleXMLRPCServer(("127.0.0.1", self.__port), CrossDomainXMLRPCRequestHandler, logRequests=self.__logRequests)
        self.__server.register_instance(self.State)
        self.__server.register_introspection_functions()

        #start server
        self.__running = True
        self.__server.serve_forever()
Exemple #2
0
def start_server(obj):
	"""
		Purpose:
		Start the XML-RPC server and register the "obj" class.
	"""
	try:
		commandServer = SimpleXMLRPCServer(('', 9000), allow_none=True)

		commandServer.register_introspection_functions()
		commandServer.register_instance(obj)

		print("{} - Starting to server forever".format(time.asctime()))
		#Now keep the server alive till killed or system reboots
		commandServer.serve_forever()

	except KeyboardInterrupt as err:
		print("{} - Keyboard Interrupt. Exiting.".format(time.asctime()))
		return

	except Exception as err:
		print(err)
		raise err

	except System.Exception as err:
		print(err)
		raise err
 def _start(self):
     """
     Used internally to start the XML-RPC server.
     """
     s = SimpleXMLRPCServer(("", getPort(self.url)), logRequests=False)
     s.register_instance(self)
     s.serve_forever()
Exemple #4
0
def runServers(xmlrpc=False,tcpPy=False):
    """Run python telnet server and info socket. They will be run at localhost on ports 9000 (or higher if used) and 21000 (or higer if used) respectively.
    
    The python telnet server accepts only connection from localhost,
    after authentication by random cookie, which is printed on stdout
    at server startup.

    The info socket provides read-only access to several simulation parameters
    at runtime. Each connection receives pickled dictionary with those values.
    This socket is primarily used by woo-multi batch scheduler.
    """
    if tcpPy:
        import woo.runtime
        srv=GenericTCPServer(handler=woo.remote.PythonConsoleSocketEmulator,title='TCP python prompt',cookie=True,minPort=9000)
        woo.runtime.cookie=srv.server.cookie
    if xmlrpc:
        if future.utils.PY3: from xmlrpc.server import SimpleXMLRPCServer
        else: from SimpleXMLRPCServer import SimpleXMLRPCServer
        port,maxPort=21000,65535 # minimum port number
        while port<maxPort:
            try:
                info=SimpleXMLRPCServer(('',port),logRequests=False,allow_none=True); break
            except socket.error: port+=1
        if port==maxPort: raise RuntimeError("No free port to listen on in range 21000-%d"%maxPort)
        # register methods, as per http://docs.python.org/library/simplexmlrpcserver.html#simplexmlrpcserver-example
        info.register_instance(InfoProvider()) # gets all defined methods by introspection
        #prov=InfoProvider()
        #for m in prov.exposedMethods(): info.register_function(m)
        _runInBackground(info.serve_forever)
        print('XMLRPC info provider on http://localhost:%d'%port)
    sys.stdout.flush()
Exemple #5
0
class Server(threading.Thread):
	"""
	Thread for incoming messages (server side of the peer)
	"""
	def __init__(self, peer):
		threading.Thread.__init__(self)
		self.loop = True
		self.peer = peer
		try:
			self.server = SimpleXMLRPCServer((peer.IPaddr, peer.portno), allow_none=True, logRequests = False) # we change this for not show unnecessary messages
			self.server.register_instance(self.peer)
		except Exception as e:
			print(e)
			sys.exit(0)
	
	def log(self, *msg):
		print("[%s]" % self.peer.name, *msg)
	
	def stop(self):
		self.server.server_close()
		self.loop = False

	def run(self):
		while self.loop:
			#self.log("xmlrpc server is handling a request...")
			self.server.handle_request()
		self.log("Server Done!")
Exemple #6
0
def rpcserver():
    server = SimpleXMLRPCServer(('localhost', 8000), requestHandler=TestRequestHandler)
    server.register_introspection_functions()
    server.register_function(pow)
    server.register_function(adder_func, 'add')
    server.register_instance(TestRPCClass())

    server.serve_forever()
def run_xmlrpc_server():
  port = 1210
  oo_proxy = OOProxy()
  #server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", port))
  server = SimpleXMLRPCServer(("localhost", port))
  server.register_instance(oo_proxy)
  #Go into the main listener loop
  server.serve_forever()
 def xmlsvr(self):
     """
     Server xml-rpc thread el thread.
     :return: void
     """
     server = SimpleXMLRPCServer(("", self.port))
     print("Listening on port %d..." % self.port)
     server.register_instance(self)
     server.serve_forever()
Exemple #9
0
def start():
    server = SimpleXMLRPCServer((HOST, PORT),
                                requestHandler=RequestHandler,
                                allow_none=True,
                                use_builtin_types=True)
    server.register_instance(ServerHandler())
    logging.info("Server is listening on " + HOST + ":" + str(PORT) + "/" +
                 ENDPOINT)
    server.serve_forever()
Exemple #10
0
def main():
    server_address = ('localhost', 10000)
    server = SimpleXMLRPCServer(server_address)
    xmlrpc_service = CalcService()
    server.register_instance(xmlrpc_service)
    server.register_introspection_functions()

    print("CTRL-C to stop")
    server.serve_forever()
    def test_exposeClass(self):
        """Expose an entire class and test the _dispatch method."""
        server = SimpleXMLRPCServer((HOST, PORT + 3))
        server.register_instance(MyService())
        ServerThread(server).start()

        # Access the exposed service.
        client = xmlrpc.client.ServerProxy("http://%s:%d" % (HOST, PORT + 3))
        self.assertEqual(client.squared(10), 100)
Exemple #12
0
def serve_agent(agent: Agent, address: str, port: int) -> None:
    """Serve agent on specified bind address and port number."""
    server = SimpleXMLRPCServer((address, port), allow_none=True)
    server.register_instance(agent)
    print('Listening on ', address, ':', port, sep="")
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #13
0
def run_server(strategy=Terminal(), port=49000):
    """Create the RPC server and share the entire strategy object."""
    #hostname = socket.gethostname()
    hostname = "0.0.0.0"    # be greedy and listen on all local interfaces
    IP = socket.gethostbyname(hostname)
    server = SimpleXMLRPCServer((IP, port), allow_none=True, logRequests=False)
    print("Listening on %s:%d" % (IP, port) )
    server.register_instance(strategy)
    server.serve_forever()
Exemple #14
0
    def test_exposeClass(self):
        """Expose an entire class and test the _dispatch method."""
        server = SimpleXMLRPCServer((HOST, PORT + 3))
        server.register_instance(MyService())
        ServerThread(server).start()

        # Access the exposed service.
        client = xmlrpc.client.ServerProxy("http://%s:%d" % (HOST, PORT + 3))
        self.assertEqual(client.squared(10), 100)
Exemple #15
0
def start():
    #NOTE: bots directory should always be on PYTHONPATH - otherwise it will not start.
    #***command line arguments**************************
    usage = '''
    This is "%(name)s" version %(version)s, part of Bots open source edi translator (http://bots.sourceforge.net).
    Server program that ensures only a single bots-engine runs at any time, and no engine run requests are
    lost/discarded. Each request goes to a queue and is run in sequence when the previous run completes.
    Use of the job queue is optional and must be configured in bots.ini (jobqueue section, enabled = True).
    Usage:
        %(name)s  -c<directory>
    Options:
        -c<directory>   directory for configuration files (default: config).

    ''' % {'name': os.path.basename(sys.argv[0]), 'version': 3.3}
    configdir = 'config'
    for arg in sys.argv[1:]:
        if arg.startswith('-c'):
            configdir = arg[2:]
            if not configdir:
                print('Error: configuration directory indicated, but no directory name.')
                sys.exit(1)
        else:
            print(usage)
            sys.exit(0)
    #***end handling command line arguments**************************
    #~ botsinit.generalinit(configdir)     #find locating of bots, configfiles, init paths etc.
    #~ if not botsglobal.ini.getboolean('jobqueue','enabled',False):
        #~ print('Error: bots jobqueue cannot start; not enabled in %s/bots.ini'%(configdir))
        #~ sys.exit(1)
    nr_threads = 2  # botsglobal.ini.getint('jobqueue','nr_threads')
    process_name = 'jobqueue'
    #~ logger = botsinit.initserverlogging(process_name)
    #~ logger.log(25,'Bots %(process_name)s started.',{'process_name':process_name})
    #~ logger.log(25,'Bots %(process_name)s configdir: "%(configdir)s".',{'process_name':process_name,'configdir':botsglobal.ini.get('directories','config')})
    port = 28082  # botsglobal.ini.getint('jobqueue','port',28082)
    #~ logger.log(25,'Bots %(process_name)s listens for xmlrpc at port: "%(port)s".',{'process_name':process_name,'port':port})

    #start launcher thread
    lauchfrequency = 5  # botsglobal.ini.getint('jobqueue','lauchfrequency',5)
    maxruntime = 60  # botsglobal.ini.getint('settings','maxruntime',60)
    for thread in range(nr_threads)
        launcher_thread = threading.Thread(name='launcher', target=launcher,
                                           args=(logger, queue, lauchfrequency, maxruntime))
        launcher_thread.start()
        #~ logger.info('Jobqueue launcher started.')

    #the main thread is the xmlrpc server: all adding, getting etc for jobqueue is done via xmlrpc.
    #~ logger.info('Jobqueue server started.')
    server = SimpleXMLRPCServer(('localhost', port), logRequests=False)
    server.register_instance(Jobqueue(logger))
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass

    sys.exit(0)
def start(configdir):
    """Server program that ensures only a single bots-engine runs at any time,
    and no engine run requests are lost/discarded.

    Each request goes to a queue and is run in sequence when the previous run completes.
    Use of the job queue is optional and must be configured in bots.ini (jobqueue section, enabled = True).
    """

    botsinit.generalinit(configdir)
    if not botsglobal.ini.getboolean('jobqueue', 'enabled', False):
        print('Error: bots jobqueue cannot start; not enabled in {}/bots.ini'.
              format(configdir))
        sys.exit(1)
    nr_threads = 2  # botsglobal.ini.getint('jobqueue','nr_threads')
    process_name = 'jobqueue'

    logger = botsinit.initserverlogging(process_name)
    logger.log(25, 'Bots %(process_name)s started.',
               {'process_name': process_name})
    logger.log(
        25, 'Bots %(process_name)s configdir: "%(configdir)s".', {
            'process_name': process_name,
            'configdir': botsglobal.ini.get('directories', 'config')
        })
    port = botsglobal.ini.getint('jobqueue', 'port', 28082)
    logger.log(
        25, 'Bots %(process_name)s listens for xmlrpc at port: "%(port)s".', {
            'process_name': process_name,
            'port': port
        })

    # start launcher thread
    q = queue.Queue()

    lauchfrequency = botsglobal.ini.getint('jobqueue', 'lauchfrequency', 5)
    maxruntime = botsglobal.ini.getint('settings', 'maxruntime', 60)
    for thread in range(nr_threads):
        launcher_thread = threading.Thread(
            name='launcher',
            target=launcher,
            args=(logger, q, lauchfrequency, maxruntime),
        )
        launcher_thread.start()

    # the main thread is the xmlrpc server:
    # all adding, getting etc for jobqueue is done via xmlrpc.
    logger.info('Jobqueue server started.')
    server = SimpleXMLRPCServer(('localhost', port), logRequests=False)
    server.register_instance(Jobqueue(logger))

    try:
        server.serve_forever()
    except (KeyboardInterrupt, SystemExit) as e:  # noqa
        pass

    sys.exit(0)
class Server:
    def __init__(self, name, port):
        self.server = SimpleXMLRPCServer((name, port),
                                         requestHandler=CARequestHandler)
        self.server.register_introspection_functions()
        self.server.register_instance(CentralAuthority(name))

    def run(self):
        # Run the server's main loop
        self.server.serve_forever()
Exemple #18
0
def main():
    logging.basicConfig(filename='worker.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s:%(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
    print("Starting mapper connection..")
    logging.info('Starting worker server connection.')
    worker = Worker()

    server = SimpleXMLRPCServer(("", 3389), allow_none=True)

    server.register_instance(worker)
    server.serve_forever()
Exemple #19
0
def main():
    # Create server
    server = SimpleXMLRPCServer(("localhost", 9004),
                                requestHandler=RequestHandler)
    server.register_introspection_functions()

    server.register_instance(RegisteredFunctions())

    # Run the server's main loop
    server.serve_forever()
Exemple #20
0
def serve_player(player, address, port):
    """Serve player on specified bind address and port number."""
    from xmlrpc.server import SimpleXMLRPCServer
    server = SimpleXMLRPCServer((address, port))
    server.register_instance(player)
    print("Listening on " + address + ":" + str(port))
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #21
0
def serve_agent(agent, address, port):
    """Serve agent on specified bind address and port number."""
    from xmlrpc.server import SimpleXMLRPCServer
    server = SimpleXMLRPCServer((address, port), allow_none=True)
    server.register_instance(agent)
    print("Listening on ", address, ":", port, sep="")
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #22
0
def serve_player(player, address, port):
    """Serve player on specified bind address and port number."""
    from xmlrpc.server import SimpleXMLRPCServer
    server = SimpleXMLRPCServer((address, port))
    server.register_instance(player)
    print("Listening on " + address + ":" + str(port))
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #23
0
def serve_agent(agent, address, port):
    """Serve agent on specified bind address and port number."""
    from xmlrpc.server import SimpleXMLRPCServer
    server = SimpleXMLRPCServer((address, port), allow_none=True)
    server.register_instance(agent)
    print("Listening on ", address, ":", port, sep="")
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #24
0
class RPCServer(threading.Thread):
    """
    The RPCServer thread provides an API for external programs to interact
    with MOM.
    """
    def __init__(self, config, momFuncs):
        threading.Thread.__init__(self, name="RPCServer")
        self.setDaemon(True)
        self.config = config
        self.momFuncs = momFuncs
        self.logger = logging.getLogger('mom.RPCServer')
        self.server = None
        self.start()

    def thread_ok(self):
        if self.server is None:
            return True
        return self.isAlive()

    def create_server(self):
        try:
            unix_port = None
            port = self.config.getint('main', 'rpc-port')
        except ValueError:
            port = None
            unix_port = self.config.get('main', 'rpc-port')
            self.logger.info("Using unix socket "+unix_port)

        if unix_port is None and (port is None or port < 0):
            return None

        if unix_port:
            self.server = UnixXmlRpcServer(unix_port)
        else:
            self.server = SimpleXMLRPCServer(("localhost", port),
                            requestHandler=RequestHandler, logRequests=0)

        self.server.register_introspection_functions()
        self.server.register_instance(self.momFuncs)

    def shutdown(self):
        if self.server is not None:
            self.server.shutdown()

    def run(self):
        try:
            self.create_server()
            if self.server is not None:
                self.logger.info("RPC Server starting")
                self.server.serve_forever()
                self.logger.info("RPC Server ending")
            else:
                self.logger.info("RPC Server is disabled")
        except Exception as e:
            self.logger.error("RPC Server crashed", exc_info=True)
Exemple #25
0
	def _start(self):


# Restrict to a particular path.

		s = SimpleXMLRPCServer(("",self.port),requestHandler=RequestHandler)
		s.register_instance(self)
		s.register_introspection_functions()


		s.serve_forever()
Exemple #26
0
class ServerThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.localServer = SimpleXMLRPCServer((HOST, PORT),
                                              requestHandler=RequestHandler,
                                              allow_none=True)
        self.localServer.register_introspection_functions()
        self.localServer.register_instance(RemoteProcedures())

    def run(self):
        self.localServer.serve_forever()
def start_server(address, port):
    server = SimpleXMLRPCServer((address, port))
    server.register_instance(ServerAgent(), allow_dotted_names=True)
    server.register_introspection_functions()
    server.register_multicall_functions()
    print('Serving XML-RPC on localhost port 8000')
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print("\nKeyboard interrupt received, exiting. Shutting down server.")
        sys.exit(0)
Exemple #28
0
 def _start(self):
     s = SimpleXMLRPCServer(("", self.port),
                            requestHandler=RequestHandler,
                            logRequests=False)
     s.register_instance(self)
     # h = s.get_request()
     # x = h[1]
     s.register_introspection_functions()
     print("server start....")
     self.server = s
     s.serve_forever()
Exemple #29
0
def main(host, port, log_level, config):
    app = CountingApp(config)
    server = SimpleXMLRPCServer(('0', port), logRequests=True, allow_none=True)
    server.register_introspection_functions()
    server.register_instance(app)

    try:
        print('Use Control-C to exit')
        server.serve_forever()
    except KeyboardInterrupt:
        print('Exiting...')
    def run(self):
        """Starts the xmlrpc callback server"""
        log("%s.%s", self.__class__.__name__, self.run.__name__)

        log("Serving on port %s ...", self.port)

        server = SimpleXMLRPCServer(("", self.port),
                                    allow_none=True, logRequests=False)
        server.register_instance(self.callback)
        server.register_introspection_functions()
        server.serve_forever()
Exemple #31
0
def main(port, data):
    # Create server
    server = SimpleXMLRPCServer(('0.0.0.0', port),
                                requestHandler=RequestHandler,
                                use_builtin_types=True,
                                allow_none=True)
    server.register_introspection_functions()
    server.register_instance(LevelDB(data))

    # Run the server's main loop
    server.serve_forever()
def run_xmlrpc_server(host, port):
    # build proxy
    oo_proxy = OOProxy()

    # start rpc server
    server = SimpleXMLRPCServer((host, port))
    server.register_instance(oo_proxy)

    # listener loop
    server.serve_forever()

    return
Exemple #33
0
class GutenTagServerThread(threading.Thread):
    def __init__(self, gtdb):
        threading.Thread.__init__(self)
        self._gtdb = gtdb

        self._server = SimpleXMLRPCServer(("localhost", gtag_common.RPC_PORT))
        self._server.register_introspection_functions()
        self._server.register_instance(self._gtdb)

    def run(self):
        self._gtdb.openDb()
        self._server.serve_forever()
Exemple #34
0
def main():
    logging.basicConfig(format="%(asctime)s %(levelname)s "
                               "%(filename)s:%(lineno)d %(message)s")

    LOG.setLevel(logging.INFO)

    LOG.info("psutil version %s at %s", psutil.__version__, psutil.__file__)

    server = SimpleXMLRPCServer(("0.0.0.0", 9002))
    server.register_introspection_functions()
    server.register_instance(MonHelperRPCInterface())
    server.serve_forever()
Exemple #35
0
 def _start(self):
     '''
     Start the server part of client.
     '''
     global PORT
     global ADDRESS
     try:
         server = SimpleXMLRPCServer((ADDRESS, PORT))
         server.register_instance(self)
         server.serve_forever()
     except:
         PORT += 1
         self._start()
Exemple #36
0
class RoboServer:
    """Cria a instancia do servidor responsavel pela comunicacao XML-RPC com o robo"""
    def __init__(self, robo, ip, port):
        self.robo = robo
        self.ip = ip
        self.port = int(port)

    def start(self):
        print("Starting XML-RPC Server...")
        self.server = SimpleXMLRPCServer((self.ip, self.port), allow_none=True)
        self.server.register_instance(self.robo)
        print("Serving XML-RPC...")
        self.server.serve_forever()
Exemple #37
0
def main():
    host = "localhost"
    port = 7500

    data_handler = DatabaseHandler()
    
    try:
        server = SimpleXMLRPCServer((host, port))
        server.register_instance(data_handler)
        server.serve_forever()
    except KeyboardInterrupt:
        print("Caught control-c, closing database connection")
        data_handler.close()
Exemple #38
0
 def __init__(self):
     super(ServerAgent, self).__init__()
     
     logging.basicConfig(level=logging.DEBUG)
     server = SimpleXMLRPCServer(('localhost', 9999), logRequests=True)
     print("Listening on localhost:9999")
     server.register_instance(self)
     server.register_introspection_functions()
     server.register_multicall_functions()
     #server.serve_forever()
     thread = threading.Thread(target=server.serve_forever)
     thread.start()
     print("Server thread started")
Exemple #39
0
def all_systems_go():
    dao = DAO(session())
    instance = ClockServer(dao)

    server = SimpleXMLRPCServer(("localhost", 8080),
                                requestHandler=RequestHandler,
                                logRequests=False,
                                allow_none=True)
    server.register_introspection_functions()
    server.register_instance(instance)

    mainlog.info("The server is running")
    server.serve_forever()
 def _start(self):
     '''
     Start the server part of client.
     '''
     global PORT
     global ADDRESS
     try:
         server = SimpleXMLRPCServer((ADDRESS, PORT))
         server.register_instance(self)
         server.serve_forever()
     except:
         PORT+=1
         self._start()
Exemple #41
0
class XmlRpcServer(object):
	"""
		XMLRPC service, exported functions are in class _RpcFuncs
	"""
	def __init__(self, host, port):
		self._server = SimpleXMLRPCServer((host, port))
		self._server.register_introspection_functions()
		self._server.register_instance(_RpcFuncs())
		logger.info('Listening for XMLRPC clients on %s:%d', host, port)
		self._server.serve_forever()

	def shutdown(self):
		self._server.shutdown()
class RemoteController(metaclass=Singleton):
    """
        Provide control over a SimpleXMLRPCServer.
    """
    def __init__(self, ip='localhost', port=8070):
        try:
            self.server = SimpleXMLRPCServer((ip, port),
                                             allow_none=True,
                                             logRequests=False)
            self._announcer = Announcer()
        except OSError as error:
            # If address already in use
            if error.errno == 98:
                raise Exception(
                    "Only one application instance can use this module")
            else:
                raise error

        self.server.register_introspection_functions()
        self.server.register_instance(RemoteDispatcher())

    @async_function
    def start(self):
        logging.info('REMOTE: Session started at ' +
                     str(self.server.server_address))

        self._announcer.start()
        self.server.serve_forever()  # Blocking
        self._announcer.stop()

        logging.info('REMOTE: Session ended')

    def stop(self):
        self.server.shutdown()

    @staticmethod
    def connect_to(uri):
        proxy = ServerProxy(uri, transport=TimeoutTransport())

        try:
            # Call a fictive method.
            proxy._()
        except Fault:
            # Connected, the method doesn't exist, which is expected.
            pass
        except socket.error:
            # Not connected, socket error mean that the service is unreachable.
            raise OSError('Session at ' + uri + ' is unreachable')

        # Just in case the method is registered in the XmlRPC server
        return proxy
class RemoteController(metaclass=Singleton):
    """
        Provide control over a SimpleXMLRPCServer.
    """

    def __init__(self, ip='localhost', port=8070):
        try:
            self.server = SimpleXMLRPCServer((ip, port), allow_none=True,
                                             logRequests=False)
            self._announcer = Announcer()
        except OSError as error:
            # If address already in use
            if error.errno == 98:
                raise Exception(
                    "Only one application instance can use this module")
            else:
                raise error

        self.server.register_introspection_functions()
        self.server.register_instance(RemoteDispatcher())

    @async
    def start(self):
        logging.info('REMOTE: Session started at ' +
                     str(self.server.server_address))

        self._announcer.start()
        self.server.serve_forever()  # Blocking
        self._announcer.stop()

        logging.info('REMOTE: Session ended')

    def stop(self):
        self.server.shutdown()

    @staticmethod
    def connect_to(uri):
        proxy = ServerProxy(uri, transport=TimeoutTransport())

        try:
            # Call a fictive method.
            proxy._()
        except Fault:
            # Connected, the method doesn't exist, which is expected.
            pass
        except socket.error:
            # Not connected, socket error mean that the service is unreachable.
            raise OSError('Session at ' + uri + ' is unreachable')

        # Just in case the method is registered in the XmlRPC server
        return proxy
def main():
    opt = parse_cmdline()
    logging.basicConfig(format="%(asctime)s %(levelname)s "
                               "%(filename)s:%(lineno)d %(message)s")

    LOG.setLevel(logging.INFO)

    LOG.info("psutil version %s at %s", psutil.__version__, psutil.__file__)

    server = SimpleXMLRPCServer((opt.ip, opt.port))
    LOG.info("listening at %s:%s", opt.ip, opt.port)
    server.register_introspection_functions()
    server.register_instance(MonHelperRPCInterface())
    server.serve_forever()
 def _start(self):
     '''
     Start the main server
     '''
     # Start the server.
     try:
         server = SimpleXMLRPCServer((gethostbyname(gethostname()),self.port))
         server.register_instance(self)
         print ('Start the main server successfully')
         print('The URL of this server is '+gethostbyname(gethostname())+':'+str(self.port))
         print('Copy this address to client.')
         server.serve_forever()
     except:
         self.port+=1
         self._start()
Exemple #46
0
def startServer(box): 

    # Restrict to a particular path.
    class RequestHandler(SimpleXMLRPCRequestHandler):
        rpc_paths = ('/RPC2',)

    # Create server
    server = SimpleXMLRPCServer(("0.0.0.0", 8000),
                                requestHandler=RequestHandler, allow_none=True)
    server.register_introspection_functions()
    
    server.register_instance(box)
    
    # Run the server's main loop
    server.serve_forever()
Exemple #47
0
def start_server(obj):
	"""
		Purpose:
		Create the XML-RPC Server to allow CPython (and other tools) to interact with
		the dksikuli instance and its Sikuli functions.

		Similar to remotesrv.py's "start_server" function.
	"""
	guiServer = SimpleXMLRPCServer(('', 8080), allow_none=True)

	guiServer.register_introspection_functions()
	guiServer.register_instance(obj)

	#Now keep the server alive till the end of the run
	guiServer.serve_forever()
Exemple #48
0
class TeacherProxy(object):
    def __init__(self, teacher):
        self._quit = False

        self._teacher = teacher
        self.server = SimpleXMLRPCServer(('0.0.0.0', 8080), logRequests=False, allow_none=True)
        self.server.register_instance(self, allow_dotted_names=True)
        Thread(target = self.run).start()

    def run(self):
        while not self._quit:
            self.server.handle_request()

    def add_winner(self, winner_uuid):
        self._teacher.add_winner(winner_uuid)
Exemple #49
0
def start(configdir):
    """Server program that ensures only a single bots-engine runs at any time,
    and no engine run requests are lost/discarded.

    Each request goes to a queue and is run in sequence when the previous run completes.
    Use of the job queue is optional and must be configured in bots.ini (jobqueue section, enabled = True).
    """

    botsinit.generalinit(configdir)
    if not botsglobal.ini.getboolean('jobqueue', 'enabled', False):
        print('Error: bots jobqueue cannot start; not enabled in {}/bots.ini'.format(configdir))
        sys.exit(1)
    nr_threads = 2  # botsglobal.ini.getint('jobqueue','nr_threads')
    process_name = 'jobqueue'

    logger = botsinit.initserverlogging(process_name)
    logger.log(25, 'Bots %(process_name)s started.', {'process_name': process_name})
    logger.log(25, 'Bots %(process_name)s configdir: "%(configdir)s".', {
               'process_name': process_name, 'configdir': botsglobal.ini.get('directories', 'config')})
    port = botsglobal.ini.getint('jobqueue', 'port', 28082)
    logger.log(25, 'Bots %(process_name)s listens for xmlrpc at port: "%(port)s".',
               {'process_name': process_name, 'port': port})

    # start launcher thread
    q = queue.Queue()

    lauchfrequency = botsglobal.ini.getint('jobqueue', 'lauchfrequency', 5)
    maxruntime = botsglobal.ini.getint('settings', 'maxruntime', 60)
    for thread in range(nr_threads):
        launcher_thread = threading.Thread(
            name='launcher',
            target=launcher,
            args=(logger, q, lauchfrequency, maxruntime),
            )
        launcher_thread.start()

    # the main thread is the xmlrpc server:
    # all adding, getting etc for jobqueue is done via xmlrpc.
    logger.info('Jobqueue server started.')
    server = SimpleXMLRPCServer(('localhost', port), logRequests=False)
    server.register_instance(Jobqueue(logger))

    try:
        server.serve_forever()
    except (KeyboardInterrupt, SystemExit) as e:  # noqa
        pass

    sys.exit(0)
	def start_server(self):
		"""
			Purpose:
			Start the XML-RPC server and register the "postrun" class.

		"""
		servicemanager.LogInfoMsg("Running in 'start_server'")

		postrunObj = postrun()
		commandServer = SimpleXMLRPCServer(("localhost", 9000), allow_none=True)

		commandServer.register_introspection_functions()
		commandServer.register_instance(postrunObj)

		#Now keep the server alive till the end of the run
		guiServer.serve_forever()
Exemple #51
0
class RemoteController(Thread, metaclass=Singleton):

    def __init__(self, ip='localhost', port=8070):
        super().__init__(daemon=True)
        self.setName('RemoteController')

        self.server = SimpleXMLRPCServer((ip, port), allow_none=True,
                                         logRequests=False)

        self.server.register_introspection_functions()
        self.server.register_instance(RemoteDispatcher())

        self._announcer = Announcer()

    def start(self):
        self._announcer.start()
        Thread.start(self)

    def run(self):
        logging.info('REMOTE: Session started at ' +
                     str(self.server.server_address))

        self.server.serve_forever()

        logging.info('REMOTE: Session ended')

    def stop(self):
        self.server.shutdown()
        self._announcer.stop()

    @staticmethod
    def connect_to(uri):
        proxy = ServerProxy(uri, transport=TimeoutTransport())

        try:
            # Call a fictive method.
            proxy._()
        except Fault:
            # Connected, the method doesn't exist, which is expected.
            pass
        except socket.error:
            # Not connected, socket error mean that the service is unreachable.
            raise Exception('Session at ' + uri + ' is unreachable')

        # Just in case the method is registered in the XmlRPC server
        return proxy
Exemple #52
0
def main():
    autoWait()
    ea = ScreenEA()

    server = SimpleXMLRPCServer(("localhost", 9000))
    server.register_function(is_connected, "is_connected")

    server.register_function(wrapper_get_raw, "get_raw")
    server.register_function(wrapper_get_function, "get_function")
    server.register_function(wrapper_Heads, "Heads")
    server.register_function(wrapper_Functions, "Functions")

    server.register_instance(IDAWrapper())

    server.register_function(wrapper_quit, "quit")
    server.serve_forever()

    qexit(0)
class PilotwireServer:

    def __init__(self, port, debug, controller_name):
        self.xmlrpc_server = SimpleXMLRPCServer(('', port), logRequests=debug)
        manager = DriverManager(
            namespace='pilotwire.controller',
            name=controller_name,
            invoke_on_load=True,
        )
        self.controller = manager.driver
        self.xmlrpc_server.register_instance(XMLRPCMethods(self.controller))

    def start(self):
        self.xmlrpc_server.serve_forever()

    def stop(self):
        self.xmlrpc_server.shutdown()
        self.xmlrpc_server.server_close()
def main(args=None):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--address', '-a', default='0.0.0.0', help='the '
                        'address on which the server is listening (e.g., '
                        '"127.0.0.1", default "0.0.0.0").')
    parser.add_argument('--port', '-p', type=int, default=9002, help='the port'
                        ' on which the server is listening (default "9002").')
    args = parser.parse_args(args)

    logging.basicConfig(format="%(asctime)s %(levelname)s "
                               "%(filename)s:%(lineno)d %(message)s")

    LOG.setLevel(logging.INFO)

    LOG.info("psutil version %s at %s", psutil.__version__, psutil.__file__)

    server = SimpleXMLRPCServer((args.address, args.port))
    LOG.info("serving on %s:%d", args.address, args.port)
    server.register_introspection_functions()
    server.register_instance(MonHelperRPCInterface())
    server.serve_forever()
Exemple #55
0
class TableProxy(object):
    def __init__(self, table):
        self._table = table
        self.server = SimpleXMLRPCServer(('0.0.0.0', 8000), logRequests=False, allow_none=True)
        self.server.register_instance(self, allow_dotted_names=True)
        Thread(target=self.server.serve_forever).start()

    def get_table_state(self, playerID):
        return self._table.output_state(table._player_dict.get(playerID, None))

    def add_player(self, host, port, playerID, name, stack):
        self._table.add_player(host, port, playerID, name, stack)

    def remove_player(self, playerID):
        self._table.remove_player(playerID)

    def run_game(self):
        self._table.run_game()

    def run_forever(self):
        self._table.start()
Exemple #56
0
class PlayerControlProxy(object):
    def __init__(self, player):
        self._quit = False

        self._player = player
        self.server = SimpleXMLRPCServer((self._player.host, self._player.port), logRequests=False, allow_none=True)
        self.server.register_instance(self, allow_dotted_names=True)
        Thread(target=self.run).start()

    def run(self):
        while not self._quit:
            self.server.handle_request()

    def player_move(self, output_spec):
        return self._player.player_move(output_spec)

    def print_table(self, table_state):
        self._player.print_table(table_state)

    def join(self):
        self._player.add_player()

    def rejoin_new(self, ai_id="unchanged"):
        self._player.rejoin_new(ai_id)

    def rejoin(self, ai_type=0):
        self._player.rejoin()

    def get_ai_id(self):
        return self._player.get_ai_id()

    def save_ai_state(self):
        self._player.save_ai_state()

    def delete_ai(self):
        self._player.delete_ai()

    def quit(self):
        self._player.server.remove_player(self._player.playerID)
        self._quit = True
Exemple #57
0
        '--url',
        dest='url',
        help='Interoperability Server URL, example: http://10.10.130.10:80',
        required=True)
    parser.add_argument(
        '--username',
        dest='username',
        help='Interoperability Username, example: calpoly-broncos',
        required=True)
    parser.add_argument('--password',
                        dest='password',
                        help='Interoperability Password, example: 4597630144',
                        required=True)

    cmd_args = parser.parse_args()
    relay = RelayService(url=cmd_args.url,
                         username=cmd_args.username,
                         password=cmd_args.password)

    server = SimpleXMLRPCServer(
        ('127.0.0.1', 9000),
        logRequests=True,
        allow_none=True)
    server.register_instance(relay)

    try:
        print('Use Control-C to exit')
        server.serve_forever()
    except KeyboardInterrupt:
        print('Exiting')
Exemple #58
0
class XMLRPCPlugin(Plugin):
    def __init__(self, name, ui):
        Plugin.__init__(self, name, ui)
        host = options["Plugin", "xmlrpc_host"]
        port = options["Plugin", "xmlrpc_port"]
        path = options["Plugin", "xmlrpc_path"]
        self.server = SimpleXMLRPCServer((host, port))
        self.server.RequestHandlerClass.rpc_paths = (path,)
        self.server.register_instance(self)
        self.thread = threading.Thread(target=self.server.serve_forever)
        self.thread.setDaemon(True)
        self.thread.start()
    def _dispatch(self, method, params):
        if method in ("score", "score_mime", "train", "train_mime"):
            return getattr(self, method)(*params)
        else:
            raise xmlrpc.client.Fault(404, '"%s" is not supported' % method)
    def train(self, form_dict, extra_tokens, attachments, is_spam=True):
        newdict = {}
        for (i, k) in list(form_dict.items()):
            if isinstance(k, str):
                k = k.encode("utf-8")
            newdict[i] = k
        mime_message = form_to_mime(newdict, extra_tokens, attachments)
        mime_message = str(mime_message.as_string(), "utf-8").encode("utf-8")
        self.train_mime(mime_message, "utf-8", is_spam)
        return ""
    def train_mime(self, msg_text, encoding, is_spam):
        if self.state.bayes is None:
            self.state.create_workers()
        if isinstance(msg_text, str):
            msg_text = str(msg_text, encoding)
        if isinstance(msg_text, str):
            msg_text = msg_text.encode("utf-8")
        msg = message_from_string(msg_text,
                                  _class=spambayes.message.SBHeaderMessage)
        if is_spam:
            desired_corpus = "spamCorpus"
        else:
            desired_corpus = "hamCorpus"
        if hasattr(self, desired_corpus):
            corpus = getattr(self, desired_corpus)
        else:
            if hasattr(self, "state"):
                corpus = getattr(self.state, desired_corpus)
                setattr(self, desired_corpus, corpus)
                self.msg_name_func = self.state.getNewMessageName
            else:
                if is_spam:
                    fn = storage.get_pathname_option("Storage",
                                                     "spam_cache")
                else:
                    fn = storage.get_pathname_option("Storage",
                                                     "ham_cache")
                storage.ensureDir(fn)
                if options["Storage", "cache_use_gzip"]:
                    factory = FileCorpus.GzipFileMessageFactory()
                else:
                    factory = FileCorpus.FileMessageFactory()
                age = options["Storage", "cache_expiry_days"]*24*60*60
                corpus = FileCorpus.ExpiryFileCorpus(age, factory, fn,
                                                     '[0123456789\-]*',
                                                     cacheSize=20)
                setattr(self, desired_corpus, corpus)
                class UniqueNamer(object):
                    count = -1
                    def generate_name(self):
                        self.count += 1
                        return "%10.10d-%d" % (int(time.time()), self.count)
                Namer = UniqueNamer()
                self.msg_name_func = Namer.generate_name
        key = self.msg_name_func()
        mime_message = str(msg.as_string(), "utf-8").encode("utf-8")
        msg = corpus.makeMessage(key, mime_message)
        msg.setId(key)
        corpus.addMessage(msg)
        msg.RememberTrained(is_spam)
    def train_spam(self, form_dict, extra_tokens, attachments):
        pass
    def train_ham(self, form_dict, extra_tokens, attachments):
        pass
    def score(self, form_dict, extra_tokens, attachments):
        """Score a dictionary + extra tokens."""
        newdict = {}
        for (i, k) in list(form_dict.items()):
            if isinstance(k, str):
                k = k.encode("utf-8")
            newdict[i] = k
        mime_message = form_to_mime(newdict, extra_tokens, attachments)
        mime_message = str(mime_message.as_string(), "utf-8").encode("utf-8")
        return self.score_mime(mime_message, "utf-8")
    def score_mime(self, msg_text, encoding):
        """Score a message representing a MIME document.
        The msg argument will be a string in the given encoding.
        """
        if self.state.bayes is None:
            self.state.create_workers()
        if isinstance(msg_text, str):
            msg_text = str(msg_text, encoding)
        if isinstance(msg_text, str):
            msg_text = msg_text.encode("utf-8")
        msg = message_from_string(msg_text,
                                  _class=spambayes.message.SBHeaderMessage)
        tokens = tokenize(msg)
        prob, clues = self.state.bayes.spamprob(tokens, evidence=True)
        msg.addSBHeaders(prob, clues)
        self.state.record_classification(msg.GetClassification(), prob)
        if not self.state.is_test and options["Storage", "cache_messages"]:
            msg.setId(self.state.getNewMessageName())
            makeMessage = self.state.unknownCorpus.makeMessage
            message = makeMessage(msg.getId(), msg.as_string())
            self.state.unknownCorpus.addMessage(message)
        return prob