[omniORB] omniOrbPy: any way to actively talk to two different servers on different hosts from a single python script?

wtflanders at micron.com wtflanders at micron.com
Thu Apr 19 09:14:54 BST 2007


Works Great!
I new there had to be a way.
Thanks, 
Bill

-----Original Message-----
From: Duncan Grisby [mailto:duncan at grisby.org] 
Sent: Wednesday, April 18, 2007 4:45 PM
To: wtflanders
Cc: omniorb-list at omniorb-support.com
Subject: Re: [omniORB] omniOrbPy: any way to actively talk to two
different servers on different hosts from a single python script? 

On Wednesday 18 April, wtflanders at micron.com wrote:

> The attached example modifies the echo ns samples.  The client is made
> into a class that accepts the system name where the echo server is
> running.  I then invoke two instances of the client to two different
> host naming services each with the echo ns srv running on it.  I
> modified the echo ns srv sample to return the host name with the
echoed
> message.  I also modified the client to accept two different host name
> on the command line.
>  
> It doesn't work, it only talks to the echo server on the first host.
It
> appears the ORB in the client is static and can only talk to one
naming
> service host.

The ORB is a singleton. It is only initialised once, so you can only
give it one set of initial references.

However, there is absolutely nothing special about the initial
references, or the naming service. If you want to access multiple naming
services, just access them. There's no need to register them as initial
references. As Tom says, you quite possibly shouldn't use more than one
naming service, but if you want or need to, there's nothing stopping
you.

You can just use code like this:

    orb = CORBA.ORB_init(sys.argv)

    hosts = [ "host1", "host2", "host3" ]

    for host in hosts:
        obj = orb.string_to_object("corbaloc::%s:2809/NameService" %
host)
        ns  = obj._narrow(CosNaming.NamingContextExt)

        if ns is None:
            # skip it
            continue

        echo = ns.resolve_str("test.mycontext/ExampleEcho.Object")
        echo = echo._narrow(Example.Echo)

        if echo is not None:
            print echo.echoString("Hello " + host)


I've missed out the exception handling for clarity, but you should get
the idea. Not a call to resolve_initial_references in sight.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --



More information about the omniORB-list mailing list