[Ace-users] How can I make such a Message_Block

kun niu haoniukun at gmail.com
Mon Dec 3 03:41:48 CST 2007


Hi all,

I'm trying to make my program make use of ACE_Message_Block.
My client is not written with ACE.
And it sends me the message like this:
the first four bytes represent the length of the following text
message in network byte order(big endian) and including the '\0'
character
following these bytes, I'll get my real message in clear text.
For example, my message might look like this:
00 00 00 06 'h' 'e' 'l' 'l' 'o' '\0'
And I want to pack them into an ACE_Message_Block.
So I used the constructor ACE_Message_Block block(buffer, length)
Then I have the following code:
block.wr_ptr(length);
ACE_InputCDR cdr(&block);
cdr.reset_byte_order(0);
ACE_CDR::ULong str_length;
cdr>>str_length;
cout<<str_length<<endl;
char str_buffer[1024];
cdr.read_char_array(str_buffer, bytes_received-4);
cout<<str_buffer<<endl;

But I found that the output are all wrong.
Would anyone please help me to solve the problem?

Any help would be appreciated and thanks in advance.


More information about the Ace-users mailing list