Answer the question
In order to leave comments, you need to log in
How to generate a set of bytes to send via a Windows socket?
Hello.
I work with the device using the SCPI protocol. Unfortunately, it is not implemented in the device according to the standard and requires each message to be preceded by its length. This is not described in the documentation, so I had to get to this with the help of a sniffer.
The sniffer tells me that the original program from the device manufacturer sends the message length in this format
Send: Return Code: 0x00000000
00000000 00 00 00 06
Copied from the SocketSniff program. Those. in 8 byte format.
Now the question is how to form char arr[] so that these 8 bytes would be in it.
I tried doing like this
std::stringstream ss;
ss << std::hex << 0x0000000000000006;
printf("x=%s\n", ss.str().c_str());
char ss[4] = {0};
sprintf(ss,"%16X",6);
printf("ss=%s\n", ff);
Answer the question
In order to leave comments, you need to log in
std::uint64_t length = GetMessageLength(); // ну тут наверное разбирешся
length = host_to_bigendian(length); // смотри для своей платформы как перевести в big endian
const char* lengthBytes = static_cast<const char*>(&length); // в памяти все и так как нужно уже лежит
send(socket, lengthBytes, sizeof(length));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question