Example
How does it work? A quick example.
- The programmer writes a module 'test' containing a class 'testclass', which will be accessed remotely.
- The server creates one or more instances of the 'testclass', and registers them with the Pyro Naming Service.
- The client queries the Naming Service for the location of those objects. It gets a Pyro URI for them.
- The client asks Pyro to create proxies for the remote object URIs.
- As the proxy appears just like the real 'testclass', the client can now invoke methods on the remote objects, as if it were normal (local) objects.
Minimal example code: the Server
import Pyro.core
import Pyro.naming
class JokeGen(Pyro.core.ObjBase):
def joke(self, name):
return "Sorry "+name+", I don't know any jokes."
daemon=Pyro.core.Daemon()
ns=Pyro.naming.NameServerLocator().getNS()
daemon.useNameServer(ns)
uri=daemon.connect(JokeGen(),"jokegen")
daemon.requestLoop()
Minimal example code: the Client
import Pyro.core
# finds object automatically if you're running the Name Server.
jokes = Pyro.core.getProxyForURI("PYRONAME://jokegen")
print jokes.joke("Irmen")
Don't like having to start a Name Server? Want to know more?
Head over to the manual and see what your options are.