1 #include "MessengerC.h"
2 #include "tao/CodecFactory/CodecFactory.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
8 parse_args (int argc
, ACE_TCHAR
*argv
[])
10 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
13 while ((c
= get_opts ()) != -1)
17 ior
= get_opts
.opt_arg ();
22 ACE_ERROR_RETURN ((LM_ERROR
,
29 // Indicates successful parsing of the command line
34 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
38 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
40 if (parse_args (argc
, argv
) != 0)
44 CORBA::Object_var obj
= orb
->string_to_object(ior
);
47 Messenger_var messenger
= Messenger::_narrow( obj
.in());
48 if(CORBA::is_nil( messenger
.in())) {
49 ACE_ERROR_RETURN ((LM_ERROR
,
50 " (%P|%t) Panic: nil reference\n"),
54 // Obtain a reference to the CodecFactory.
55 CORBA::Object_var obj2
=
56 orb
->resolve_initial_references ("CodecFactory");
58 IOP::CodecFactory_var codec_factory
=
59 IOP::CodecFactory::_narrow (obj2
.in ());
61 // Set up a structure that contains information necessary to
62 // create a GIOP 1.2 CDR encapsulation Codec.
63 IOP::Encoding encoding
;
64 encoding
.format
= IOP::ENCODING_CDR_ENCAPS
;
65 encoding
.major_version
= 1;
66 encoding
.minor_version
= 2;
68 // Obtain the CDR encapsulation Codec.
69 IOP::Codec_var codec
=
70 codec_factory
->create_codec (encoding
);
72 CORBA::String_var user_name
= CORBA::string_dup ("Ru");
74 CORBA::Any user_name_as_any
;
75 user_name_as_any
<<= user_name
.in ();
77 CORBA::OctetSeq_var client_user_name
= codec
->encode (user_name_as_any
);
79 messenger
->send_message (client_user_name
.in ());
81 messenger
->shutdown ();
85 catch( const CORBA::SystemException
&ex
) {
86 ex
._tao_print_exception ("Caught CORBA exception: ");