I am using TCP/IP socket programming. I have a floating point value stored in a variable ret_val in my server code which I want to send to the client which is waiting to receive it.
How can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you know that both client and server are the same platform etc., you can simply use
sizeof(float)to determine your buffer size and copy that many bytes from the address of your float.As soon as your client/server are different platforms/different languages etc. you’ll have to start worrying about how to portably encode the float. But for a simple approach, the above will work fine.