Generally, a name service needs to be started in a CORBA program and then bound or parsed In the Naming Service. As for binding and parsing, the content is actually a reference of the CORBA object.
The principle of not using the Naming Service for communication is actually very simple, that is, you do not need to bind the Naming Service, parse the reference, and change the way to deal with this interaction process. There are many types of transmitted content, such as ior, corbaloc, and file. I am using the IOR value.
The ior is actually obtained from the orb. object_to_string (object) method, and then the IOR is changed to a CORBA object using Orb. string_to_object (string.
Get some code
Server:
Try {
// Create and initialize the orb
Orb orb = orb. INIT (ARGs, null );
// Get reference to rootpoa & activate the poamanager
POA rootpoa =
(PoA) orb. resolve_initial_references ("rootpoa ");
Rootpoa. the_poamanager (). Activate ();
// Create servant and register it with the orb
Commimpl helloimpl = new commimpl ();
Helloimpl. setorb (ORB );
// Get object reference from the servant
Org. Omg. CORBA. Object ref =
Rootpoa. servant_to_reference (helloimpl );
System. Out. println (ORB. object_to_string (REF); // print the IOR string
System. Out. println
("Test Server Ready and waiting ...");
// Wait for invocations from clients
Orb. Run ();
}
Catch (exception e ){
System. Err. println ("error:" + E );
E. printstacktrace (system. Out );
}
System. Out. println ("testserver exiting ...");
Client code:
Try {
// Create and initialize the orb
Orb orb = orb. INIT (ARGs, null );
System. Out. println ("orb initialised/N ");
Org. Omg. CORBA. Object objref = orb. string_to_object ("IOR:" + ior); ior is the string printed by the server.
Agentimpl = agenthelper. Narrow (objref );
Dataevent Dvin = new dataevent ();
Dvin. eventname = "testin ";
Dvin. eventno = 1;
Dvin. Protocol = "";
Dvin. recvername = "";
Dvin. sendername = "";
Dvin. Data = "testin". getbytes ();
Dataeventholder holder = new dataeventholder ();
Int result = agentimpl. excute (Dvin, holder );
Dataevent out = holder. value;
System. Out. println ("reulst:" + Result + "out:" + out. eventname );
} Catch (exception e ){
System. Out. println ("error:" + E );
E. printstacktrace (system. Out );
}
Simply put, you do not need to search for "nameservice" nodes in the Naming Service, and do not need to bind nodes. You can communicate directly.