1
votes

I would like to ask about the problems I'm going to get when I transfer strings from one computer to another with different endianness.

I'm reading the data transferred into a std::deque<char>, and then parse it to std::string.

I can imagine that if my computer is LE (little endian) and the computer on the other hand is BE (big endian), then all I have to do is reverse the order of the bytes in total before queuing them and parsing them.

What about PDP endianness? can it be fixed?

Or is this whole idea of fixing wrong because endianness doesn't matter when I transfer a series of 1-byte chars?

1
The transfer itself isn't affected by endianness, it's only a factor in the applications on either side. If you're using binary dumps of values more than a byte in size, the endianness must agree on both sides or there must be a transformation - but it will be at the level of individual values, not the whole file. The only way to do this sanely is to define an endianness for the values within the file and have the app interpret those bytes as appropriate. - Mark Ransom

1 Answers

1
votes

It shouldn't matter for 1 byte chars, unless they are interpreted as wider integers on either side.

In case of wider integers though, you should be converting your values to network order before writing them to the network. The receiver will convert them from network to host order on their side.

You typically use the hton/ntoh family of functions for this.