Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java_server thread: How to resolve hostname when calling CORBA object


Message #1 by "Lucky Door" <luckydoor@y...> on Wed, 21 Mar 2001 16:43:28
I am trying to create a java client to communicate with
orbix object created with C++. I checked the C++ client
and it communicate with server via NameService without 
specifying "hostname". In java code (from Wrox book), I 
see the client code has to specify hostname where the
CORBA server resides. 

sample code from wrox book:

// Client implementation
import org.omg.CORBA.*;
import org.omg.CosNaming.*;

public class TestClient {
    public static void main(String[] args) {

        try {
            // initialize ORB
            ORB orb = ORB.init(args, null);

            // connecting to the Naming Service
            org.omg.CORBA.Object contextObj = 
                orb.resolve_initial_references("NameService");
            NamingContext rootContext
=                                          
NamingContextHelper.narrow(contextObj);
            
            // get object reference
            NameComponent name = new NameComponent("Test", "");
            NameComponent path[] = {
                name
            };

            // retreive object
            org.omg.CORBA.Object obj = rootContext.resolve(path);
            Test testObj = TestHelper.narrow(obj);
            
            // invoke methods
            short result1 = testObj.method1((short) 1, "Test");
            String result2 = testObj.method2((short) 1, "Test");
            
            System.out.println("Result 1 is " + result1);
            System.out.println("Result 2 is " + result2);

            // release object
            testObj._release();
        } catch (Exception e) {
            System.err.println("Exception : " + e);
            e.printStackTrace(System.err);
        }
    }
}


to run the client, I have to specify the hostname:

java TestClient -ORBInitialPort <X> -ORBInitialHost <hostname>

How can I locate the server if I don't know the hostname via
Naming Service?


Thanks,

  Return to Index