Mega Search
23.2 Million


Sign Up

Make a donation  
How to transport 0x00 through TIdBytes  
News Group: borland.public.cppbuilder.internet.socket

Would you be so kind and help?

I have been using UDP communication for a while (BC++ 6.0). While 
transfering the projects from BDS2006 C++ to CodeGear 2007 C++,  I have some 
problems with sending 0x00 byte.
Indy 9 (BDS2006) uses char[] for transport buffer, Indy 10 uses TIdBytes for 
transport buffer (as far as I know).
I can not use TIdBytes for transport 0x00.
We are using TIdUDPServer and TIdUDPClient components for industrial 
automation communication, where 0x00 is valid data.
The sample code is below (tried to use other ways to fill TIdBytes, but 
allways with same result).

//-------------------------------------------------------------------------
 TIdBytes cbuf;
 char c[8];

 c[0]=0x01;
 c[1]=0x00;
 c[2]='a';
 c[3]='b';
 c[4]=0x00;
 c[5]='c';
 c[6]='d';

 cbuf.Length=8;
 RawToBytesF(cbuf,c,8);

UdpServ->SendBuffer(shost,iport,cbuf);

//-------------------------------------------------------------------------
//Getting as follows; cbuf[0]=0x01,cbuf[1]=0x00 - and nothing further

It seems that TIdBytes uses 0x00 as null termination for string. Am I doing 
something wrong or this kind is a feature of Indy 10 (or bug) ?

Appreciate any suggestion..

Best regards, Marijan





Vote for best question.
Score: 0  # Vote:  0
Date Posted: 6-Jan-2008, at 12:47 PM EST
From: Marijan Sever
 
Re: How to transport 0x00 through TIdBytes  
News Group: borland.public.cppbuilder.internet.socket
"Marijan Sever"  wrote in message 
news:4780bfd0@newsgroups.borland.com...

> I have some problems with sending 0x00 byte.

Then you are not sending the bytes correctly, because Indy does not treat 
0x00 any differently than other bytes.

> Indy 9 (BDS2006) uses char[] for transport buffer

No, it used void* instead, which meant you could pass in just about anything 
you wanted.

> Indy 10 uses TIdBytes for transport buffer (as far as I know).

There are several different ways to send buffers in Indy 10.  TIdBytes is 
just one of them.

> I can not use TIdBytes for transport 0x00.

0x00 works fine with TIdBytes.

> TIdBytes cbuf;
> char c[8];

You don't need a separate char[].  You can fill the TIdBytes directly, ie:

    TIdBytes cbuf;
    cbuf.Length = 8;
    cbuf[0] = 0x01;
    cbuf[1] = 0x00;
    cbuf[2] = 'a';
    cbuf[3] = 'b';
    cbuf[4] = 0x00;
    cbuf[5] = 'c';
    cbuf[6] = 'd';
    cbuf[7] = ?; // what are you putting here???  You allocate 8 slots but 
only fill in 7 of them

> //Getting as follows

Getting where?  Were are you looking at the data from?  The receiver end? 
If you are sending 8 bytes but only receiving 2 bytes, then that is all you 
are receiving.  What do you have set for the TIdUDPServer.BufferSize 
property?  What does your OnUDPRead event handler look like?  Have you tried 
using a packet sniffer to verify all of the bytes are arriving on the 
receiver's network adpater to begin with?

> It seems that TIdBytes uses 0x00 as null termination for string.

No, it does not.  The full Length of the buffer is always used.


Gambit 



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 7-Jan-2008, at 9:40 AM EST
From: Remy Lebeau \(TeamB\)