FTP tools, instead of the getfile module. But instead of spilling all the beans here, I’ll
just say, “Read on.”
Using Serial Ports
Sockets, the main subject of this chapter, are the programmer’s interface to network
connections in Python scripts. As we’ve seen, they let us write scripts that converse
with computers arbitrarily located on a network, and they form the backbone of the
Internet and the Web.
If you’re looking for a lower-level way to communicate with devices in general, though,
you may also be interested in the topic of Python’s serial port interfaces. This isn’t quite
related to Internet scripting, but it’s similar enough in spirit and is discussed often
enough on the Net to merit a few words here.
In brief, scripts can use serial port interfaces to engage in low-level communication with
things like mice, modems, and a wide variety of serial devices and hardware. Serial port
interfaces are also used to communicate with devices connected over infrared ports
(e.g., hand-held computers and remote modems). Such interfaces let scripts tap into
raw data streams and implement device protocols of their own. Other Python tools
such as the ctypes and struct modules may provide additional tools for creating and
extracting the packed binary data these ports transfer.
At this writing, there are a variety of ways to send and receive data over serial ports in
Python scripts. Notable among these options is an open source extension package
known as pySerial, which allows Python scripts to control serial ports on both Windows
and Linux, as well as BSD Unix, Jython (for Java), and IronPython (for .Net and Mono).
Unfortunately, there is not enough space to cover this or any other serial port option
in any sort of detail in this text. As always, see your favorite web search engine for up-
to-date details on this front.
A Simple Python File Server | 851