[omniORB] C++ client to Java server

Andrew Parkin AndrewP@eigroup.com
Mon, 19 Feb 2001 08:17:27 -0000


Hi all,

I wonder whether anyone can help - I have written a Corba server in Java
that uses the Naming Service on port 1050 to expose the SMSRef object (code
below).  This is running on the Java 2 ORB supplied with JDK1.2.2.

I am trying to connect to this using a C++ client and OmniOrb but cannot
seem to get it to work.  If both programs are on the same machine I can make
a connection by cutting and pasting the stringified reference (instead of
using the Naming Service) and everything works fine, but if the two clients
are on separate machines I cannot get the C++ client to locate the Java
server.  I have tried numerous examples I have found but without any
success.  If anyone can throw any light on this I would really appreciate
it!  Thanks.

Andrew Parkin



Java server code follows:


Properties props = new Properties();
props.put("org.omg.CORBA.ORBInitialPort", "1050");
ORB orb = ORB.init(args, props);

SMSCorba SMSRef = new SMSCorba();
orb.connect(SMSRef);

NamingContext ctx =
NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
NamingContext objref = ctx;

NameComponent nc1 = new NameComponent("SMSCorba", "text");
NameComponent[] name1 = {nc1};
ctx.rebind(name1, SMSRef);





C++ client code follows:


CosNaming::NamingContext_var rootContext;
		
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");

try
{
	// Obtain a reference to the root context of the Name service:
	CORBA::Object_var obj;
	// obj =
orb->resolve_initial_references("corbaloc:iiop:remoteServer:1050#NameService
"); // this doesn't work either
	obj =
orb->resolve_initial_references("corbaname::remoteServer:1050");

	// Narrow the reference returned.
	rootContext = CosNaming::NamingContext::_narrow(obj);
	if( CORBA::is_nil(rootContext))
	{
		cerr << "Failed to narrow the root naming context." << endl;
	}
}
catch(CORBA::ORB::InvalidName& ex)
{
	// This should not happen!
	cerr << "Service required is invalid [does not exist]." << endl;
}

// Create a name object, containing the name test/context:
CosNaming::Name name;
name.length(1);
name[0].id   = (const char*) "SMSCorba";
name[0].kind = (const char*) "text";

try
{
	// Resolve the name to an object reference.
	rootContext->resolve(name);
}
catch(CosNaming::NamingContext::NotFound& ex)
{
	// This exception is thrown if any of the components of the
	// path [contexts or the object] aren't found:
	cerr << "Context not found." << endl;
}
catch(CORBA::COMM_FAILURE& ex)
{
	cerr << "Caught system exception COMM_FAILURE -- unable to contact
the "
		<< "naming service." << endl;
}
catch(CORBA::SystemException&)
{
	cerr << "Caught a CORBA::SystemException while using the naming
service." << endl;
}