diff options
author | CAM Gerlach <CAM.Gerlach@Gerlach.CAM> | 2022-06-09 13:55:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 13:55:06 (GMT) |
commit | a5ba0f4ebca5020f6c77718a20663e0ac6e194ac (patch) | |
tree | 955d4afbe49793d5fc3310741bc25f239963e901 /Doc/howto | |
parent | a365dd64c2a1f0d142540d5031003f24986f489f (diff) | |
download | cpython-a5ba0f4ebca5020f6c77718a20663e0ac6e194ac.zip cpython-a5ba0f4ebca5020f6c77718a20663e0ac6e194ac.tar.gz cpython-a5ba0f4ebca5020f6c77718a20663e0ac6e194ac.tar.bz2 |
Doc: Update references and examples of old, unsupported OSes and uarches (GH-92791)
Diffstat (limited to 'Doc/howto')
-rw-r--r-- | Doc/howto/sockets.rst | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Doc/howto/sockets.rst b/Doc/howto/sockets.rst index e58f78a..0bbf97d 100644 --- a/Doc/howto/sockets.rst +++ b/Doc/howto/sockets.rst @@ -252,20 +252,25 @@ Binary Data ----------- It is perfectly possible to send binary data over a socket. The major problem is -that not all machines use the same formats for binary data. For example, a -Motorola chip will represent a 16 bit integer with the value 1 as the two hex -bytes 00 01. Intel and DEC, however, are byte-reversed - that same 1 is 01 00. +that not all machines use the same formats for binary data. For example, +`network byte order <https://en.wikipedia.org/wiki/Endianness#Networking>`_ +is big-endian, with the most significant byte first, +so a 16 bit integer with the value ``1`` would be the two hex bytes ``00 01``. +However, most common processors (x86/AMD64, ARM, RISC-V), are little-endian, +with the least significant byte first - that same ``1`` would be ``01 00``. + Socket libraries have calls for converting 16 and 32 bit integers - ``ntohl, htonl, ntohs, htons`` where "n" means *network* and "h" means *host*, "s" means *short* and "l" means *long*. Where network order is host order, these do nothing, but where the machine is byte-reversed, these swap the bytes around appropriately. -In these days of 32 bit machines, the ascii representation of binary data is +In these days of 64-bit machines, the ASCII representation of binary data is frequently smaller than the binary representation. That's because a surprising -amount of the time, all those longs have the value 0, or maybe 1. The string "0" -would be two bytes, while binary is four. Of course, this doesn't fit well with -fixed-length messages. Decisions, decisions. +amount of the time, most integers have the value 0, or maybe 1. +The string ``"0"`` would be two bytes, while a full 64-bit integer would be 8. +Of course, this doesn't fit well with fixed-length messages. +Decisions, decisions. Disconnecting |