Server

class compas.rpc.Server(addr, requestHandler=<class 'xmlrpc.server.SimpleXMLRPCRequestHandler'>, logRequests=True, allow_none=False, encoding=None, bind_and_activate=True, use_builtin_types=False)[source]

Bases: SimpleXMLRPCServer

Version of a SimpleXMLRPCServer that can be cleanly terminated from the client side.

Notes

This class has to be used by a service to start the XMLRPC server in a way that can be pinged to check if the server is alive, and can be cleanly terminated.

Examples

# service.py

from compas.rpc import Server
from compas.rpc import Dispatcher

class DefaultService(Dispatcher):
    pass


if __name__ == '__main__':

    server = Server(("localhost", 8888))

    server.register_function(server.ping)
    server.register_function(server.remote_shutdown)
    server.register_instance(DefaultService())
    server.serve_forever()

Methods

ping

Simple function used to check if a remote server can be reached.

remote_shutdown

Stop the server through a call from the client side.

Inherited Methods

close_request

Called to clean up an individual request.

fileno

Return socket file number.

finish_request

Finish one request by instantiating RequestHandlerClass.

get_request

Get the request and client address from the socket.

handle_error

Handle an error gracefully.

handle_request

Handle one request, possibly blocking.

handle_timeout

Called if no new request arrives within self.timeout.

process_request

Call finish_request.

register_function

Registers a function to respond to XML-RPC requests.

register_instance

Registers an instance to respond to XML-RPC requests.

register_introspection_functions

Registers the XML-RPC introspection methods in the system namespace.

register_multicall_functions

Registers the XML-RPC multicall method in the system namespace.

serve_forever

Handle one request at a time until shutdown.

server_activate

Called by constructor to activate the server.

server_bind

Called by constructor to bind the socket.

server_close

Called to clean-up the server.

service_actions

Called by the serve_forever() loop.

shutdown

Stops the serve_forever loop.

shutdown_request

Called to shutdown and close an individual request.

system_listMethods

system.listMethods() => ['add', 'subtract', 'multiple']

system_methodHelp

system.methodHelp('add') => "Adds two integers together"

system_methodSignature

system.methodSignature('add') => [double, int, int]

system_multicall

system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => [[4], ...]

verify_request

Verify the request.