How it works...

In this recipe, we have created a ServerThread subclass inheriting from the Python threading library's thread class. This subclass initializes a server attribute that creates an instance of the SimpleXMLRPC server. The XML-RPC server address can be given through the command-line input. In order to enable the multicall function, we called the register_multicall_functions() method on the server instance.

Then, four trivial functions are registered with this XML-RPC server: add(), subtract(), multiply(), and divide(). These functions do exactly the same operation as their names suggest.

In order to launch the server, we pass a host and port to the run_server() function. A server instance is created using the ServerThread class discussed earlier. The start() method of this server instance launches the XML-RPC server.

On the client side, the run_client() function accepts the same host and port arguments from the command line. It then creates a proxy instance of the XML-RPC server discussed earlier by calling the ServerProxy() class from xmlrpclib. This proxy instance is then passed onto the multicall class instance, multicall. Now, the preceding four trivial RPC methods can be run, for example, add, subtract, multiply, and divide. Finally, we can get the result through a single call, for example, multicall(). The result tuple is then printed in a single line.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.37.196