Foundations of Python Network Programming

The comprehensive guide to building network applications with Python

2nd Edition

By John Goerzen , Brandon Rhodes

Foundations of Python Network Programming Cover Image

Everything you need to know about network programming using Python, using the latest versions of Python networking modules. Foundations of Python Network Programming benefits both scripters and serious application developers who want a feature-rich, yet simple language to address web and network application coding challenges.

Full Description

  • ISBN13: 978-1-4302-3003-8
  • 368 Pages
  • User Level: Intermediate to Advanced
  • Publication Date: December 20, 2010
  • Available eBook Formats: EPUB, MOBI, PDF
  • Print Book Price: $54.99
  • eBook Price: $38.99
Buy eBook Buy Print Book Add to Wishlist

Related Titles

Full Description

This second edition of Foundations of Python Network Programming targets Python 2.5 through Python 2.7, the most popular production versions of the language. Python has made great strides since Apress released the first edition of this book back in the days of Python 2.3. The advances required new chapters to be written from the ground up, and others to be extensively revised.

You will learn fundamentals like IP, TCP, DNS and SSL by using working Python programs; you will also be able to familiarize yourself with infrastructure components like memcached and message queues. You can also delve into network server designs, and compare threaded approaches with asynchronous event-based solutions.

But the biggest change is this edition's expanded treatment of the web. The HTTP protocol is covered in extensive detail, with each feature accompanied by sample Python code. You can use your HTTP protocol expertise by studying an entire chapter on screen scraping and you can then test lxml and BeautifulSoup against a real-world web site. The chapter on web application programming now covers both the WSGI standard for component interoperability, as well as modern web frameworks like Django.

Finally, all of the old favorites from the first edition are back: E-mail protocols like SMTP, POP, and IMAP get full treatment, as does XML-RPC. You can still learn how to code Python network programs using the Telnet and FTP protocols, but you are likely to appreciate the power of more modern alternatives like the paramiko SSH2 library. If you are a Python programmer who needs to learn the network, this is the book that you want by your side.

What you’ll learn

  • Understand low level networking
  • Handle sending and receiving email including composing and decoding emails, SMTP, POP and IMAP
  • Program the lower levels of web application programming such as FastCGI and WSGI and HTTP itself
  • Learn how to use memcached and message qeues using Python
  • Access web services using Python
  • Master multitasking with threads, forking, and asynchronous communication

Who this book is for

This book will be of interest to python programmers who need to program networked applications using Python. From web application developers, to systems integrators, to system administrators—this book has everything you need to know.

Table of Contents

Table of Contents

  1. Introduction to Client/Server Networking
  2. UDP
  3. TCP
  4. Socket Names and DNS
  5. Network Data and Network Errors
  6. TLS and SSL
  7. Server Architecture
  8. Caches, Message Queues, and Map-Reduce
  9. HTTP
  10. Screen Scraping
  11. Web Applications
  12. E-mail Composition and Decoding
  13. SMTP
  14. POP
  15. IMAP
  16. Telnet and SSH
  17. FTP
  18. RPC
Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

Errata

Please Login to submit errata.

On page 21:
ephemeral range in linux as described is inaccurate, check /proc/sys/net/ipv4/ip_local_port_range

On page 21:
says that client uses recv instead of recvfrom, but code listing in book says otherwise.

On page 21:
Note that the Python program can always use a socket's getsockname() method to retrieve the current IP and port to which the socket is bound.

Warning: As documented here: http://bugs.python.org/issue1049

The behavior and return value for calling socket.socket.getsockname() on
an unconnected unbound socket is unspecified. On UNIX, it returns an
address ('0.0.0.0', 0), while on Windows it raises an obscure exception
"error: (10022, 'Invalid argument')".

On page 26:

The first code listing:

>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> s.sendto('Fake reply', ('127.0.0.1', 47873))

The indentation for the second line appears wrong. It looks like there is whitespace before the "s =", when there shouldn't be.

On page 68:

script dns_mx.py resolves the hostname of all the mx records to the same IP address.
In resolve_hostname "name = sys.argv[1]"should be changed to "name = hostname"

On page 73:

Instead of being stored as four decimal digits 4, 4, 2, and 3 with ...

should be:

Instead of being stored as four decimal digits 4, 2, 5, and 3 with ...

On page 122:

(from the queue module)

should be:

(from the Queue module)

note the capital Q

On page 243:
"remove" should be "remote" in:

"A locally stored message can be uploaded directly to one of the remove folders"