Software Design Spring 2007 RemoteObject lab exercise ------------------------- 1) Make sure Pyro is installed: python >>> import Pyro.core 1a) If not, become root and type yum install python-pyro OR wget http://wb/sd/code/Pyro-3.6.tar.gz tar -xzf Pyro-3.6.tar.gz rm Pyro-3.6.tar.gz (just being tidy) cd Pyro-3.6 su - (type the root password) ./setup.py install For more information about Pyro, see http://pyro.sourceforge.net/ 2) Download: wget http://wb/sd/code/RemoteObject.py This contains wrapper classes and some function that I wrote to make Pyro easier to use. wget http://wb/sd/code/SimpleRemoteObject.py This contains an example that demonstrates the use of my classes. 2) Find a partner and decide who will run the client and who will run the server. 3a) If you are the server, disable your firewall, and then run python SimpleRemoteObject.py your_name_here The name that you provide has to be unique. If someone else has already registered the same name on the name server, you will get an error. 3b) If you are the client, run python SimpleRemoteObject.py server_name_here 3 5 The server_name_here you provide should be the name of your partner's server. The arguments 3 and 5 are converted to strings, and sent to the remote object where they are added and the sum returned an printed. 4) Read the code from SimpleRemoteObject.py and make sure you understand how it works: class SimpleRemoteObject(RemoteObject): """this remote object exports the add method""" def add(self, x, y): print x, y return x + y def server(name): """this is the code to start a SimpleRemoteObject server""" # instantiate the object simple = SimpleRemoteObject() # find the name server and # advertise this remote object ns = NameServer() simple.connect(ns, name) # wait for requests simple.requestLoop() def client(name, x, y): """this is the code for a SimpleRemoteObject client""" # find the name server ns = NameServer() # instantiate a proxy for the remote object proxy = ns.get_proxy(name) # invoke a method on the proxy z = proxy.add(x, y) print z def main(script, name='bob', x=None, y=None, *args): if x != None and y != None: # if the user provides arguments, run as a client x = int(x) y = int(y) client(name, x, y) else: # otherwise run as a server server(name) if __name__ == '__main__': main(*sys.argv)