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

后端 未结 4 969
灰色年华
灰色年华 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:00

    You did not mean sizeof(HEX_bufferMessage). The type of HEX_bufferMessage is [presumably] char*, and the size of a char* is 8 bytes on your [64-bit] system.

    Pass the number 7 instead, preferably using a constant, and get rid of that dynamic allocation if the value 7 really is fixed.

    const int BUF_SIZE = 7;
    char HEX_bufferMessage[BUF_SIZE];
    
    // ...
    
    retorno = send(sckSloMo, &HEX_bufferMessage[0], BUF_SIZE, 0); 
    

提交回复
热议问题