#!/usr/bin/env python import sys # Import the CORBA module from omniORB import CORBA # Import the stubs for the CosNaming and Example modules import CosNaming, Example class EchoNSHostClient: def __init__ (self, nsName): self.nsHostName=nsName # Initialise the ORB self.orb = CORBA.ORB_init( ["-", "-ORBInitRef", "NameService=corbaloc:iiop:" + self.nsHostName + ":2809/NameService"] ) # Obtain a reference to the root naming context obj = self.orb.resolve_initial_references("NameService") rootContext = obj._narrow(CosNaming.NamingContext) if rootContext is None: print "Failed to narrow the root naming context" sys.exit(1) # Resolve the name "test.my_context/ExampleEcho.Object" name = [CosNaming.NameComponent("test", "my_context"), CosNaming.NameComponent("ExampleEcho", "Object")] try: obj = rootContext.resolve(name) except CosNaming.NamingContext.NotFound, ex: print "Name not found" sys.exit(1) # Narrow the object to an Example::Echo self.eo = obj._narrow(Example.Echo) if (self.eo is None): print "Object reference is not an Example::Echo" sys.exit(1) def Echo(self, message): # Invoke the echoString operation result = self.eo.echoString(message) print "I said '%s'. The object said '%s'." % (message,result) # Get the name service host name from the command line (without # checking that the arguments are sensible!) nsHostName1 = sys.argv[1] nsHostName2 = sys.argv[2] c1=EchoNSHostClient(nsHostName1) c2=EchoNSHostClient(nsHostName2) c1.Echo("A message to host "+nsHostName1) c2.Echo("A message to host "+nsHostName2)