@@ -43,10 +43,10 @@ web server it's talking to uses both "server" sockets and "client" sockets.
4343History
4444-------
4545
46- Of the various forms of IPC (* Inter Process Communication *), sockets are by far
47- the most popular. On any given platform, there are likely to be other forms of
48- IPC that are faster, but for cross-platform communication, sockets are about the
49- only game in town.
46+ Of the various forms of :abbr: ` IPC ( Inter Process Communication ) `,
47+ sockets are by far the most popular. On any given platform, there are
48+ likely to be other forms of IPC that are faster, but for
49+ cross-platform communication, sockets are about the only game in town.
5050
5151They were invented in Berkeley as part of the BSD flavor of Unix. They spread
5252like wildfire with the Internet. With good reason --- the combination of sockets
@@ -66,13 +66,14 @@ your browser did something like the following::
6666 # - the normal http port
6767 s.connect(("www.mcmillan-inc.com", 80))
6868
69- When the ``connect `` completes, the socket ``s `` can now be used to send in a
70- request for the text of this page. The same socket will read the reply, and then
71- be destroyed. That's right - destroyed. Client sockets are normally only used
72- for one exchange (or a small set of sequential exchanges).
69+ When the ``connect `` completes, the socket ``s `` can be used to send
70+ in a request for the text of the page. The same socket will read the
71+ reply, and then be destroyed. That's right, destroyed. Client sockets
72+ are normally only used for one exchange (or a small set of sequential
73+ exchanges).
7374
7475What happens in the web server is a bit more complex. First, the web server
75- creates a "server socket". ::
76+ creates a "server socket"::
7677
7778 #create an INET, STREAMing socket
7879 serversocket = socket.socket(
@@ -96,7 +97,7 @@ Finally, the argument to ``listen`` tells the socket library that we want it to
9697queue up as many as 5 connect requests (the normal max) before refusing outside
9798connections. If the rest of the code is written properly, that should be plenty.
9899
99- OK, now we have a "server" socket, listening on port 80. Now we enter the
100+ Now that we have a "server" socket, listening on port 80, we can enter the
100101mainloop of the web server::
101102
102103 while True:
@@ -145,7 +146,7 @@ perhaps a signon. But that's a design decision - it's not a rule of sockets.
145146
146147Now there are two sets of verbs to use for communication. You can use ``send ``
147148and ``recv ``, or you can transform your client socket into a file-like beast and
148- use ``read `` and ``write ``. The latter is the way Java presents their sockets.
149+ use ``read `` and ``write ``. The latter is the way Java presents its sockets.
149150I'm not going to talk about it here, except to warn you that you need to use
150151``flush `` on sockets. These are buffered "files", and a common mistake is to
151152``write `` something, and then ``read `` for a reply. Without a ``flush `` in
@@ -166,11 +167,11 @@ this connection. Ever. You may be able to send data successfully; I'll talk
166167about that some on the next page.
167168
168169A protocol like HTTP uses a socket for only one transfer. The client sends a
169- request, the reads a reply. That's it. The socket is discarded. This means that
170+ request, then reads a reply. That's it. The socket is discarded. This means that
170171a client can detect the end of the reply by receiving 0 bytes.
171172
172173But if you plan to reuse your socket for further transfers, you need to realize
173- that *there is no " EOT" (End of Transfer) on a socket. * I repeat: if a socket
174+ that *there is no * :abbr: ` EOT ( End of Transfer ) ` * on a socket. * I repeat: if a socket
174175``send `` or ``recv `` returns after handling 0 bytes, the connection has been
175176broken. If the connection has *not * been broken, you may wait on a ``recv ``
176177forever, because the socket will *not * tell you that there's nothing more to
@@ -336,7 +337,7 @@ Use ``select``.
336337
337338In C, coding ``select `` is fairly complex. In Python, it's a piece of cake, but
338339it's close enough to the C version that if you understand ``select `` in Python,
339- you'll have little trouble with it in C. ::
340+ you'll have little trouble with it in C::
340341
341342 ready_to_read, ready_to_write, in_error = \
342343 select.select(
@@ -353,9 +354,9 @@ call is blocking, but you can give it a timeout. This is generally a sensible
353354thing to do - give it a nice long timeout (say a minute) unless you have good
354355reason to do otherwise.
355356
356- In return, you will get three lists. They have the sockets that are actually
357+ In return, you will get three lists. They contain the sockets that are actually
357358readable, writable and in error. Each of these lists is a subset (possibly
358- empty) of the corresponding list you passed in. And if you put a socket in more
359+ empty) of the corresponding list you passed in. If you put a socket in more
359360than one input list, it will only be (at most) in one output list.
360361
361362If a socket is in the output readable list, you can be
0 commit comments