Cover image for Twisted Network Programming Essentials, 2nd Edition

Book description

Get started with Twisted, the event-driven networking framework written in Python. With this introductory guide, you’ll learn the key concepts and design patterns to build event-driven client and server applications for many popular networking protocols. You’ll also learn the tools to build new protocols using Twisted’s primitives.

Table of Contents

  1. Special Upgrade Offer
  2. Foreword to the First Edition
  3. Preface
    1. Why Use Twisted?
    2. What This Book Covers
    3. Conventions Used in This Book
    4. What You’ll Need
    5. Changes Since the Previous Edition
    6. Using Code Examples
    7. Safari® Books Online
    8. How to Contact Us
    9. Acknowledgments
  4. I. An Introduction to Twisted
    1. 1. Getting Started
      1. Installing Twisted
        1. Installation on Linux
          1. More package options and optional dependencies
        2. Installation on Windows
          1. Optional dependencies
          2. Adding Twisted utilities to your PATH
        3. Installation on OS X
          1. Optional dependencies
      2. Installing from Source
        1. Required Dependencies
          1. Installing a C compiler
          2. Installing zope.interface
        2. Installing Twisted from a Release Tarball
        3. Installing Twisted from a Source Checkout
        4. Installing Optional Dependencies from Source
      3. Testing Your Installation
      4. Using the Twisted Documentation
        1. API Documentation
        2. Subproject Documentation
      5. Finding Answers to Your Questions
        1. Mailing Lists
        2. IRC Channels
        3. Stack Overflow
        4. Twisted Blogs
    2. 2. Building Basic Clients and Servers
      1. A TCP Echo Server and Client
      2. Event-Driven Programming
      3. The Reactor
      4. Transports
      5. Protocols
        1. Protocol Factories
        2. Decoupling Transports and Protocols
      6. A TCP Quote Server and Client
      7. Protocol State Machines
      8. More Practice and Next Steps
    3. 3. Writing Asynchronous Code with Deferreds
      1. What Deferreds Do and Don’t Do
      2. The Structure of a Deferred Object
      3. Callback Chains and Using Deferreds in the Reactor
      4. Practice: What Do These Deferred Chains Do?
        1. Exercise 1
        2. Exercise 2
        3. Exercise 3
        4. Exercise 4
        5. Exercise 5
        6. Exercise 6
      5. The Truth About addCallbacks
        1. Exercise 7
        2. Exercise 8
      6. Key Facts About Deferreds
      7. Summary of the Deferred API
      8. More Practice and Next Steps
    4. 4. Web Servers
      1. Responding to HTTP Requests: A Low-Level Review
        1. The Structure of an HTTP Request
        2. Parsing HTTP Requests
      2. Handling GET Requests
        1. Serving Static Content
          1. Static URL dispatch
        2. Serving Dynamic Content
        3. Dynamic Dispatch
          1. Creating resources that are both renderable and have children
          2. Redirects
      3. Handling POST Requests
        1. A Minimal POST Example
      4. Asynchronous Responses
      5. More Practice and Next Steps
    5. 5. Web Clients
      1. Basic HTTP Resource Retrieval
        1. Printing a Web Resource
        2. Downloading a Web Resource
      2. Agent
        1. Requesting Resources with Agent
        2. Retrieving Response Metadata
        3. POSTing Data with Agent
      3. More Practice and Next Steps
  5. II. Building Production-Grade Twisted Services
    1. 6. Deploying Twisted Applications
      1. The Twisted Application Infrastructure
        1. Services
        2. Applications
        3. TAC Files
        4. twistd
        5. Plugins
      2. More twistd Examples
      3. More Practice and Next Steps
        1. Suggested Exercises
    2. 7. Logging
      1. Basic In-Application Logging
      2. twistd Logging
      3. Custom Loggers
      4. Key Facts and Caveats About Logging
    3. 8. Databases
      1. Nonblocking Database Queries
      2. More Practice and Next Steps
    4. 9. Authentication
      1. The Components of Twisted Cred
      2. Twisted Cred: An Example
      3. Credentials Checkers
      4. Authentication in Twisted Applications
      5. More Practice and Next Steps
    5. 10. Threads and Subprocesses
      1. Threads
      2. Subprocesses
        1. Running a Subprocess and Getting the Result
        2. Custom Process Protocols
      3. More Practice and Next Steps
    6. 11. Testing
      1. Writing and Running Twisted Unit Tests with Trial
      2. Testing Protocols
      3. Tests and the Reactor
        1. Testing Deferreds
        2. Testing the Passage of Time
      4. More Practice and Next Steps
  6. III. More Protocols and More Practice
    1. 12. Twisted Words
      1. IRC Clients
      2. IRC Servers
      3. More Practice and Next Steps
    2. 13. Twisted Mail
      1. SMTP Clients and Servers
        1. The SMTP Protocol
        2. Sending Emails Using SMTP
        3. SMTP Servers
        4. Storing Mail
      2. IMAP Clients and Servers
        1. IMAP Servers
        2. IMAP Clients
      3. POP3 Clients and Servers
        1. POP3 Servers
      4. More Practice and Next Steps
    3. 14. SSH
      1. SSH Servers
        1. A Basic SSH Server
      2. Using Public Keys for Authentication
      3. Providing an Administrative Python Shell
      4. Running Commands on a Remote Server
        1. SSH Clients
      5. More Practice and Next Steps
    4. 15. The End
      1. Contributing to Twisted
  7. Index
  8. About the Authors
  9. Colophon
  10. Special Upgrade Offer
  11. Copyright