1 #include "MessengerC.h"
2 #include "orbsvcs/CosNamingC.h"
3 #include "ace/OS_NS_unistd.h"
6 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
10 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
12 // Find the Naming Service
13 CORBA::Object_var naming_obj
= orb
->resolve_initial_references("NameService");
14 CosNaming::NamingContextExt_var root
=
15 CosNaming::NamingContextExt::_narrow(naming_obj
.in());
16 if (CORBA::is_nil(root
.in())) {
17 std::cerr
<< "Nil Naming Context reference" << std::endl
;
21 // Resolve the Messenger object
24 name
[0].id
= CORBA::string_dup( "example" );
25 name
[1].id
= CORBA::string_dup( "Messenger" );
26 CORBA::Object_var obj
= CORBA::Object::_nil();
27 while (CORBA::is_nil(obj
.in())) {
29 obj
= root
->resolve_str("example/Messenger");
30 } catch (const CosNaming::NamingContext::NotFound
&) {
31 // Sleep for a second and try again
36 // Narrow the Messenger object reference
37 Messenger_var messenger
= Messenger::_narrow(obj
.in());
38 if (CORBA::is_nil(messenger
.in())) {
39 std::cerr
<< "Not a Messenger reference" << std::endl
;
43 CORBA::String_var message
= CORBA::string_dup("Hello!");
46 messenger
->send_message("TAO User", "TAO Test", message
.inout());
48 std::cout
<< "Message was sent" << std::endl
;
52 catch(const CORBA::Exception
& ex
) {
53 std::cerr
<< "Caught a CORBA exception: " << ex
<< std::endl
;