1 #include "MessengerC.h"
2 #include "orbsvcs/CosNamingC.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior_input_file
= ACE_TEXT("file://url.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
15 while ((c
= get_opts ()) != -1)
19 ior_input_file
= get_opts
.opt_arg ();
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
35 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
39 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
41 if (parse_args (argc
, argv
) != 0)
44 // Find the Naming Service & the Message Server name in it
45 CORBA::Object_var obj
= orb
->string_to_object(ior_input_file
);
48 Messenger_var messenger
= Messenger::_narrow(obj
.in());
49 if (CORBA::is_nil(messenger
.in())) {
50 std::cerr
<< "Not a Messenger reference" << std::endl
;
54 CORBA::String_var message
= CORBA::string_dup("Hello!");
55 messenger
->send_message( "TAO User", "TAO Test", message
.inout());
57 std::cout
<< "Message was sent" << std::endl
;
59 std::cout
<< "Now try the same thing with the simple name." << std::endl
;
60 obj
= orb
->resolve_initial_references("NameService");
61 CosNaming::NamingContextExt_var root
=
62 CosNaming::NamingContextExt::_narrow(obj
.in());
63 obj
= root
->resolve_str("Simple/Messenger");
64 messenger
= Messenger::_narrow(obj
.in());
65 messenger
->send_message( "ACE User", "TAO Test", message
.inout());
67 std::cout
<< "Message was sent" << std::endl
;
69 catch(const CORBA::Exception
& ex
) {
70 std::cerr
<< "Caught a CORBA::Exception: " << ex
<< std::endl
;