The server is sending the short as big endian, the client does ntohs(),
Now for compatibility , is it better to use ntohs() or (resp[0] << 8) | (resp[1] & 0xff).
Or it wouldn't matter ?
Note: resp is an std::string and the first two bytes in it are the sent-from-server-as-big-endian short value.
You should always use ntohs and other functions from the family if you want your code to be compatible across different hardware architectures.
Network Byte Order is equal to Big Endian, but for example x86 architecture is Little Endian, so you have to swap order of bytes for them to represent a valid value.
But there are architectures which are Big Endian, and there is no need for swapping for them.
You can treat nthos as a macro, which is defined in compiler headers to:
Oh hi rr.
No pressure you don't have to do anything thing after all you've done for this game.
Now
The thing is in my server I must specify the endianess of a number when appending it to a packet.
Waya think would fit c++/ntohs ?
If you never plan to run your application on big endian processor then don't even bother about all of that and send/recv everything in little endian. just read/write the value without any conversion.
My client platform is x86/x64 windows. I don't compile for x64 but I know x86 code works on x64.
What I meant is : https://nodejs.org/api/buffer.html
I must specify the endianess of any int larger than a byte.