send() function returns more bytes that it was required c++

后端 未结 4 967
灰色年华
灰色年华 2021-01-27 06:47

I am doing a socket program and, after my server is connected with the device, I am trying to send a message to him. But the send() function returns a number of bytes greater th

4条回答
  •  借酒劲吻你
    2021-01-27 07:13

    It seems you assume that sizeof(HEX_buffer_message) yields the number of elements in HEX_buffer_message. It doesn't. It produces the size of the type of HEX_buffer_message which seems to be a 64 bit pointer yielding 8 rather than 7. There is no way to determine the size of an array allocated with new T[n] from the returned pointer. You'll need to use the n passed somehow.

提交回复
热议问题