1 #include "MessengerC.h"
2 #include "orbsvcs/CosNamingC.h"
3 #include "orbsvcs/Naming/Naming_Client.h"
4 #include "ace/OS_NS_unistd.h"
7 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
11 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
13 // Find the Naming Service
14 TAO_Naming_Client naming_client
;
16 if (naming_client
.init (orb
.in ()) != 0) {
17 std::cerr
<< "Could not initialize naming client." << 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
= naming_client
->resolve(name
);
30 } catch (const CosNaming::NamingContext::NotFound
&) {
31 // Sleep for a second and try again
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!" );
44 messenger
->send_message( "TAO User", "TAO Test", message
.inout() );
46 std::cout
<< "Message was sent" << std::endl
;
48 catch(const CORBA::Exception
& ex
) {
49 std::cerr
<< "Caught a CORBA::Exception: " << ex
<< std::endl
;