PDA

View Full Version : (char) 0x00



saman_artorious
25th June 2012, 07:20
Doese anyone know why when I append the following unsigned char to my packet, it gets missed on the other side?

packet.append((char) 0x00);

However, this does not happen always, as somewhere else in another program It gets appended to the packet.

any guesses?

Santosh Reddy
25th June 2012, 07:32
I guess packet is QByteArray.

ChrisW67
25th June 2012, 08:08
I guess that "the other side" is referring to some sort of vague networky thingamabob implemented in Haskell and using IPoAC (http://en.wikipedia.org/wiki/IP_over_Avian_Carriers). The problem is predation.

Seriously. What do you expect people to do with the information you have provided? What exactly is the problem? Does the zero byte not get added to packet (whatever that is)? Does the packet not get sent to the other side (however that happens)? Does the packet not arrive at the other side (wherever that is)? Is the packet sending protocol a reliable or unreliable one? Is the other side doing something unexpected when it sees a zero byte? Sometimes? Always? Only under certain conditions?

saman_artorious
25th June 2012, 08:54
Yes Santosh (it's nice to see you, m HCU Hyd. graduated ;))

Yes, the packet is QByteArray, and you are absolutely right!

Well, it's a UDP socket. I did not paste the code as I have already tested it. It works fine for any packet. except that 0x00 char does not get appended to it.
However, before writing to UDP, when I qDEbug the packet, it shows 0x00 correctly, but when I READUDP packet on the other machine, it misses the 0x00 from the packet.

if still not helping, I will send the code in the next post, though.... : )

wysota
25th June 2012, 08:59
0x00 is a string termination character, if you operate on your packet with any function expecting string data (i.e. taking a const char *), then 0x00 will not be considered part of the data block by that function.

saman_artorious
25th June 2012, 10:09
Yes, that's right, but all the function take QByteArray. I do not use QString at all.
Do you have any idea?

ChrisW67
25th June 2012, 10:25
I did not paste the code as I have already tested it. It works fine for any packet.
Except that it doesn't work, does it?

You are possibly assuming that a single write at one end will result in a single read at the other end: assuming that all the data sent is available when readyRead() is emited. Of course we have no way to know.

Santosh Reddy
25th June 2012, 10:26
IMO this has nothing to do with QByteArray / Udp, it may be your application which has some problem to read a 0 terminated data.

Do the transmitted bytes, and received bytes match in count?

wysota
25th June 2012, 11:25
You are possibly assuming that a single write at one end will result in a single read at the other end: assuming that all the data sent is available when readyRead() is emited. Of course we have no way to know.

He is using UDP so in this particular case, as an exception to all other similar issues we're listening to, this time this is not a problem :)

I'm still convinced we're dealing with some const char * function somewhere.