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

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

    Assuming you've got

    TYPE* myPointer;

    then sizeof(myPointer) will give you the size of the pointer (i.e. 4 bytes on a 32 bit system, 8 on a 64 bit system), not the size of the array.

    You want to do

    const int bufferSize = 7;
    HEX_bufferMessage = new CHAR[bufferSize]; 
    
    ...
    
    retorno = send(sckSloMo, HEX_bufferMessage, sizeof(CHAR) * bufferSize, 0); 
    

提交回复
热议问题