Domanda

Can anyone explain the problem of byte order when transferring data? and how it is solved with the socket interface? I would appreciate any help, thank you in advance

È stato utile?

Soluzione

Multi-byte data (2/4/8-byte integers, 2/4-byte string characters, etc) can be represented in memory in either little endian or big endian. When exchanging data between machines, especially when they use different endian architectures, the data has to be normalized during transmission. Socket API have standard hton...() (host to network) and ntoh...() (network to host) functions for that purpose. However, you have to call them yourself when preparing/receiving data, they are not called automatically since sockets only see arbitrary bytes. Higher level protocols (FTP, TCP, custom protocols, etc) dictate what the bytes represent and how they behave.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top