No Naming Service is used for communication by CORBA.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.