The simplest RPC call ever in Python:
Server (file xmlrpc.py):
def fibonacci_naive(n):
if n == 0:
return 0
if n == 1:
return 1
return fibonacci_naive(n-2) + fibonacci_naive(n-1)
import SimpleXMLRPCServer
server = SimpleXMLRPCServer.SimpleXMLRPCServer(('192.168.0.104', 8000))
server.register_function(fibonacci_naive)
server.serve_forever()
################################################################
$ python xmlrpc.py
Client:
>>> import xmlrpclib
>>> server = xmlrpclib.ServerProxy('http://192.168.0.104:8000')
>>> print server.fibonacci_naive(10)
55
No comments:
Post a Comment