server
import Pyro4
@Pyro4.expose class GreetingMaker(object): def get_fortune(self, name): return "Hello, {0}. Here is your fortune message:n" "Tomorrow's lucky number is 12345678.".format(name)
daemon = Pyro4.Daemon() # make a Pyro daemon ns = Pyro4.locateNS() # find the name server uri = daemon.register(GreetingMaker) # register the greeting maker as a Pyro object ns.register("example.greeting", uri) # register the object with a name in the name server
print("Ready.") daemon.requestLoop() # start the event loop of the server to wait for calls
client
saved as greeting-client.py
import Pyro4
name = input("What is your name? ").strip()
greeting_maker = Pyro4.Proxy("PYRONAME:example.greeting") # use name server object lookup uri shortcut print(greeting_maker.get_fortune(name))