Hi,

i am really confused. I have to write data to a socket due to a protocol. first i send 4 bytes (network byte order). This is the length of a message.
then i send a message (sequence of binary data or ascii data). But the server does not recognize my request. Sometimes i have to send data twice and string contains wrong data.


Ok this is my message length definition
TUint8 buf[4];
then defining command id and length (here always =1 <- command id)
TInt32 lenMessage;
TInt32 CommandID;

buffer definition
HBufC8* buffer;

...
buffer = HBufC8::NewL( 8 );

next i convert the length
lenMessage= 1;
BigEndian::Put32(buf, lenMessage);
fill the buffer...
buffer->Des().Append(buf, 4);
now prepare buffer with command id

CommandID = 1;
BigEndian::Put32(buf, CommandID);

buffer->Des().Append(buf, 4);
now send my "command" to my desired socket endpoint

socket.Write( *buffer, status) ;

User::WaitForRequest(status); //sync only for testing purposes

and then reset the buffer...
and send username to the socket

buffer = HBufC8::NewL( 9 ); //5+4

lenMessage = 5;
BigEndian::Put32(buf, lenMessage);

buffer->Des().Append(buf, 4);

buffer->Des().Append( _LIT8("username") );

socket.Write( *buffer, status) ;

User::WaitForRequest(status); //sync only for testing purposes


is there a better approach? username will be send with special characters so i think there goes something wrong.
If i think about the memory layout of HBufC8 the first byte is the length and then follows data. Is this correct?
So i think this is different from my format: first 4 byte length then string data as a sequence of ascii data.



Greetz
Franky