Server implementations¶
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.
-
class
tinyrpc.server.
RPCServer
(transport, protocol, dispatcher)¶ High level RPC server.
Parameters: - transport – The
RPCTransport
to use. - protocol – The
RPCProtocol
to use. - dispatcher – The
RPCDispatcher
to use.
-
serve_forever
()¶ Handle requests forever.
Starts the server loop in which the transport will be polled 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 resultung request and the return value (either an error or a result) will be sent back to the client using the transport.
After calling
_spawn()
, the server will fetch the next message and repeat.
- transport – The