Chapter 10. Network Programming
Introduction
Credit: Guido van Rossum, creator of Python
Network programming is one of my
favorite Python applications. I wrote or started most of the network
modules in the Python standard library, including the
socket and select extension
modules and most of the protocol client modules (such as
ftplib), which set an example. I also wrote a
popular server framework module, SocketServer, and
two web browsers in Python, the first predating Mosaic. Need I say
more?
Python’s roots lie in a distributed operating system, Amoeba, which I helped design and implement in the late ’80s. Python was originally intended to be the scripting language for Amoeba, since it turned out that the Unix shell, while ported to Amoeba, wasn’t very useful for writing Amoeba system-administration scripts. Of course, I designed Python to be platform-independent from the start. Once Python was ported from Amoeba to Unix, I taught myself BSD socket programming by wrapping the socket primitives in a Python extension module and then experimenting with them using Python; this was one of the first extension modules.
This approach proved to be a great early testimony of
Python’s strengths. Writing socket code in C is
tedious: the code necessary to do error checking on every call
quickly overtakes the logic of the program. Quick: in which order
should a server call accept,
bind, connect, and
listen? This is remarkably difficult to find out if all you have is a set of Unix manpages. In ...