Sending floating point number from server to client

后端 未结 3 875
醉酒成梦
醉酒成梦 2021-01-15 10:26

I am using TCP/IP socket programming. I have a floating point value stored in a variable ret_val in my server cod

3条回答
  •  失恋的感觉
    2021-01-15 10:54

    float f = ...;
    size_t float_size = sizeof(float);
    const char* buffer = (const char *) &f;
    send(mySocket, buffer, float_size, 0);
    

    This code will work fine if both the server and client use the same platform. If the platforms are different, you will have to negotiate message sizes and endianess explicitly.

提交回复
热议问题