関数を動的に登録できます (サーバーの起動後)。
#Server side code:
import sys
from SimpleXMLRPCServer import SimpleXMLRPCServer
def dynRegFunc(): #this function will be registered dynamically, from the client
return True
def registerFunction(function): #this function will register with the given name
server.register_function(getattr(sys.modules[__name__], str(function)))
if __name__ == '__main__':
server = SimpleXMLRPCServer((address, port)), allow_none = True)
server.register_function(registerFunction)
server.serve_forever()
#Client side code:
import xmlrpclib
if __name__ == '__main__':
proxy = xmlrpclib.ServerProxy('http://'+str(address)+':'+str(port), allow_none = True)
#if you'd try to call the function dynRegFunc now, it wouldnt work, since it's not registered -> proxy.dynRegFunc() would fail to execute
#register function dynamically:
proxy.registerFunction("dynRegFunc")
#call the newly registered function
proxy.dynRegFunc() #should work now!