I am trying new the C++ socket programming. I am having some difficulty for understanding functionality of htons, htonl and related functions. I read some documents but still my questions are as follows,
for a single server and and single client I am using htons both side for the port number and the code is working fine. Even if I don't use these functions and both my server-clients are Intel based 64 bit machines, the codes are working fine. But what if multiple clients try to connect my server and the clients use different data storage format. For example, x86 is little-endian and ARM A-53 is both little- and big-endian and others, where some of them are 32 bits, 16 bits or 64 bits etc. My server is 64 bits. So I'm now confused which functions I have to use that uniformly serves all purpose ? Or, I have to always detect the client type and convert it's data format (port number) to 64 bit (as my server is 64 bit) and then use htonl() function to reach the server. It would be great someone please reply or points me out if I am on the wrong path ...
It's good that you're asking the question. It shows that you're worrying about the right things.
Documentation here:
http://linux.die.net/man/3/htonl
note that the arguments and return types have specific sizes no matter which system you're on.