Reputation: 53
I want to send a string over a socket, but have to worry about endianness. The only way I know how to fix this is using htonl, but to my knowledge that only works on strings. How can I send a string over a socket?
Upvotes: 1
Views: 1260
Reputation: 564
I don't believe you have to do anything for strings (I'm assuming char* UTF-8) since characters are only one byte in length, so you do not have to worry about endianness. You only need to worry about byte ordering if your data is more than 1 byte in length (e.g. short, long, etc.).
Here's a wiki article explaining this topic in much greater detail.
Upvotes: 4