0

Am writing a server program in c++ using winsock running on a x86 arch. I was wondering if a client running on a arm based architecture can share data with the server successfully without running into problems since the two architectures use different endianness. Do I have to write some code to convert the endianness before receiving or sending data?

volt
  • 1
  • 1
  • I feel like your ARM phone connects to x86 architecture all the time. – sweenish Mar 17 '21 at 18:30
  • As long as two processes share bytes in "network byte order" (i.e. big endian), then there's no confusion. Yes, you have to check that upon encoding data to the network, the ouput is in the expected format. This is often dictated in the protocol or file format specification (like PNGs for example). – Elias Toivanen Mar 17 '21 at 19:23
  • ARM is usually used in little-endian mode (e.g. on Android phones, Raspbian, Debian), which is exactly the endianness of x86. – Ruslan Mar 17 '21 at 20:10

1 Answers1

1

Just make a decision about the endianness of the data to be sent between them, and be consistent on both sides.

Most commonly you would use network byte order, which is big-endian, and use functions like htonl, ntohl to convert to and from whatever the host system uses. (If the host system is already big-endian, these functions just do nothing and will usually be optimized out.)

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82