[Solved] Sending NULL data over a socket


Try

WriteData(std::string("\0",1));

using your function or even:

const char null_data(0);
send(newsockfd,&null_data,1,0);

to send it directly.


WriteData("00000000");

Will actually sends 8 octets of 48 [decimal] (assuming your platform is ASCII which all modern systems are compatible with).

However \0 is the escape sequence used in string literals to represent the null character (that is the zero octet).

There’s a conflation (mixing together) in C++ between the notions of characters and bytes that dates back to the earliest days of C and is pretty much baked in.

3

solved Sending NULL data over a socket