CHAPTER 13
Client-Side Scripting
“Socket to Me!”
The preceding chapter introduced Internet fundamentals and explored sockets—the
underlying communications mechanism over which bytes flow on the Net. In this
chapter, we climb the encapsulation hierarchy one level and shift our focus to Python
tools that support the client-side interfaces of common Internet protocols.
We talked about the Internet’s higher-level protocols in the abstract at the start of the
preceding chapter, and you should probably review that material if you skipped over
it the first time around. In short, protocols define the structure of the conversations
that take place to accomplish most of the Internet tasks we’re all familiar with—reading
email, transferring files by FTP, fetching web pages, and so on.
At the most basic level, all of these protocol dialogs happen over sockets using fixed
and standard message structures and ports, so in some sense this chapter builds upon
the last. But as we’ll see, Python’s protocol modules hide most of the underlying
details—scripts generally need to deal only with simple objects and methods, and Py-
thon automates the socket and messaging logic required by the protocol.
In this chapter, we’ll concentrate on the FTP and email protocol modules in Python,
and we’ll peek at a few others along the way (NNTP news, HTTP web pages, and so
on). Because it is so prevalent, we will especially focus on email in much of this chapter,
as well as in the two to follow—we’ll use tools and techniques introduced here in the
larger PyMailGUI and PyMailCGI client and server-side programs of Chapters
14 and 16.
All of the tools employed in examples here are in the standard Python library and come
with the Python system. All of the examples here are also designed to run on the client
side of a network connection—these scripts connect to an already running server to
request interaction and can be run from a basic PC or other client device (they require
only a server to converse with). And as usual, all the code here is also designed to teach
us something about Python programming in general—we’ll refactor FTP examples and
package email code to show object-oriented programming (OOP) in action.
853
Do
wnload from Wow! eBook <www.wowebook.com>