Like RPC Client, servers are top-level instances that most user code should interact with. They provide runnable functions that are combined with transports, protocols and dispatchers to form a complete RPC system.
Defines and implements a single-threaded, single-process, synchronous server.
RPCServer(transport: tinyrpc.transports.ServerTransport, protocol: tinyrpc.protocols.RPCProtocol, dispatcher: tinyrpc.dispatch.RPCDispatcher)
High level RPC server.
The server is completely generic only assuming some form of RPC communication is intended. Protocol, data transport and method dispatching are injected into the server object.
receive_one_message() → None
Handle a single request.
Polls the transport for a new message.
After a new message has arrived
_spawn()is called with a handler function and arguments to handle the request.
The handler function will try to decode the message using the supplied protocol, if that fails, an error response will be sent. After decoding the message, the dispatcher will be asked to handle the resulting request and the return value (either an error or a result) will be sent back to the client using the transport.
serve_forever() → None
Handle requests forever.
Starts the server loop; continuously calling
receive_one_message()to process the next incoming request.
Trace incoming and outgoing messages.
When this attribute is set to a callable this callable will be called directly after a message has been received and immediately after a reply is sent. The callable should accept three positional parameters:
def my_trace(direction, context, message): logger.debug('%s%s', direction, message) server = RPCServer(transport, protocol, dispatcher) server.trace = my_trace server.serve_forever()
will log all incoming and outgoing traffic of the RPC service.
Note that the
messagewill be the data stream that is transported, not the interpreted meaning of that data. It is therefore possible that the binary stream is unreadable without further translation.