Hi guys,
Your book is awesome. I just started to code the networking part, small client /server to test your code. I have a pitfall and I don't understand why you don't have it. That's some times I haven't write c++ code so I hope my problem is not too obvious.
Here we go.
When I debug my small project that is using BinaryPacket, m_Data is always empty.
Here is your code snippet from your code website =
Display All
This line is my problem =
*(u_long *)m_Data = htonl(size+sizeof(u_long));
Either one of the four bytes of the long is 0x00 (That will be more likely to be the case...), that will end the character sequence "m_Data". End of the story.(For me). And confirmed by VS debugger. m_Data is always null terminated after this line.
Say I have a size of 5(+4 sizeof(u_long)), htonl will send back 0x09000000, first byte of the long is 0x00 that is put in the first m_Data memory space. If any of those bytes aren't 0x00, that works of course.
How do you guys convert a long into a char sequence without having this null terminated behavior ?
Either I don't see something big in front of me or a specific configuration ? Logically that makes sense so I know my outdated C++ knowledge is the key.
I found this topic related to it, they don't seem to have the problem but I still do when I try
stackoverflow.com/questions/54…onvert-long-to-char-const
I looked your AttachRemotePlayer method for a BinaryPacket example. But whatever, the problem comes with the size, not the data.
What did I miss ?
Thank you and keep doing your great work.
Your book is awesome. I just started to code the networking part, small client /server to test your code. I have a pitfall and I don't understand why you don't have it. That's some times I haven't write c++ code so I hope my problem is not too obvious.
Here we go.
When I debug my small project that is using BinaryPacket, m_Data is always empty.
Here is your code snippet from your code website =
Source Code
This line is my problem =
*(u_long *)m_Data = htonl(size+sizeof(u_long));
Either one of the four bytes of the long is 0x00 (That will be more likely to be the case...), that will end the character sequence "m_Data". End of the story.(For me). And confirmed by VS debugger. m_Data is always null terminated after this line.
Say I have a size of 5(+4 sizeof(u_long)), htonl will send back 0x09000000, first byte of the long is 0x00 that is put in the first m_Data memory space. If any of those bytes aren't 0x00, that works of course.
How do you guys convert a long into a char sequence without having this null terminated behavior ?
Either I don't see something big in front of me or a specific configuration ? Logically that makes sense so I know my outdated C++ knowledge is the key.
I found this topic related to it, they don't seem to have the problem but I still do when I try
stackoverflow.com/questions/54…onvert-long-to-char-const
I looked your AttachRemotePlayer method for a BinaryPacket example. But whatever, the problem comes with the size, not the data.
What did I miss ?
Thank you and keep doing your great work.