host to network double?

前端 未结 3 749
粉色の甜心
粉色の甜心 2021-01-13 10:33

I\'d like to send some double precision floating point numbers over the network. (standard C, standard sockets) There is no htond or ntohd to convert the data to and from ne

相关标签:
3条回答
  • 2021-01-13 10:54

    You might want to look at XDR which was first defined in rfc1014. Obviously, you want to find a library which implements XDR for your platform.

    0 讨论(0)
  • 2021-01-13 10:55

    Convert it to an agreed string format and send that. Not sure if it's common practice or even decent, but it worked for me (it is true I did not care about performance at that point since I wasn't sending very many values).

    0 讨论(0)
  • 2021-01-13 11:04

    What Andre is saying is that binary floating point numbers are not trustworthy across networks because of differences between different computer architectures. Differences that go beyond byte order (big/little endian). Thus things like converting to strings or use of libraries such as XDR, is really necessary if there is any chance your data is going to be processed by different computer architectures.

    The simple formats of integers and characters can slip through with just endian adjustments but floating point gets more complex.

    0 讨论(0)
提交回复
热议问题