Results 1 to 9 of 9

Thread: (char) 0x00

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default (char) 0x00

    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?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: (char) 0x00

    I guess packet is QByteArray.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: (char) 0x00

    I guess that "the other side" is referring to some sort of vague networky thingamabob implemented in Haskell and using IPoAC. 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?

  4. #4
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: (char) 0x00

    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.... : )

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: (char) 0x00

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: (char) 0x00

    Yes, that's right, but all the function take QByteArray. I do not use QString at all.
    Do you have any idea?

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: (char) 0x00

    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.

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: (char) 0x00

    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?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: (char) 0x00

    Quote Originally Posted by ChrisW67 View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to convert unsigned char[] to char *?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 29th April 2011, 08:58
  2. char to const char* with atof
    By mickey in forum General Programming
    Replies: 5
    Last Post: 29th February 2008, 04:10
  3. Conversion from unsigned char* to unsigned char
    By santosh.kumar in forum General Programming
    Replies: 1
    Last Post: 6th August 2007, 13:12
  4. char* from QString
    By bruccutler in forum Newbie
    Replies: 16
    Last Post: 14th February 2007, 06:36
  5. c++ char to Int
    By mickey in forum General Programming
    Replies: 3
    Last Post: 4th October 2006, 23:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.