Twisted Network Programming Essentials from O'Reilly is a task-oriented look at this new open source, Python-based technology. The book begins with recommendations for various plug-ins and add-ons to enhance the basic package as installed. It then details Twisted's collection simple network protocols, and helper utilities. The book also includes projects that let you try out the Twisted framework for yourself. For example, you'll find examples of using Twisted to build web services applications using the REST architecture, using XML-RPC, and using SOAP.
Written for developers who want to start building applications using Twisted, this comprehensive guide presents examples of the most common tasks you'll face when building network applications. It also helps you understand the key concepts and design patterns used in Twisted applications. Here are just some of the topics discussed in Twisted Network Programming Essentials:
How to make TCP connections
How to use Twisted to work with the Web
Twisted's authentication framework
Usenet and SSH clients and servers
Along the way, each lesson is supported by thorough notes and explanations to make absolutely certain you're up to speed with this leading-edge Python technology.
Chapter 1 Getting Started
Installing from Source Files
Adding Twisted Utilities to Your Path
Using the Twisted Documentation
Finding Answers to Your Questions
Chapter 2 Building Simple Clients and Servers
Starting the Twisted Event Loop
Working with Asynchronous Results
Sending and Receiving Data
Accepting Connections from Clients
Chapter 3 Web Clients
Downloading a Web Page
Accessing a Password-Protected Page
Uploading a File
Checking Whether a Page Has Changed
Monitoring Download Progress
Chapter 4 Web Servers
Responding to HTTP Requests
Parsing HTTP Requests
Working with POST Data from HTML Forms
Managing a Hierarchy of Resources
Storing Web Data in an SQL Database
Running an HTTP Proxy Server
Chapter 5 Web Services and RPC
Using the REST Architecture for Web Services
Using a Web Client to Update Resources Through REST
Abe Fettig is a software developer and maintainer of Hep, an open source message server that makes it possible to transparently route information between RSS, email, weblogs, and web services. He speaks frequently at software conferences including PyCon and lives in Portland, Maine with his wife, Hannah.
About the AuthorAbe Fettig is a software developer specializing in Internet applications. He currently works as a software enginner for JotSpot, Inc. His open source projects include Yarn, a Python library that uses Twisted to transfer information between RSS, email, weblogs, and web services. Abe lives in Portland, Maine with his wife, Hannah.
ColophonOur look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects.
The image on the cover of Twisted Network Programming Essentials shows a ball of snakes. When the ground begins to thaw in spring, things heat up for some species of snakes. Males emerge from their hibernation dens cold, hungry, and randy! An estimated 50,000 male snakes can fill a location such as a limestone quarry, waiting patiently for nearby females to emerge. When they do, the mating frenzy begins, and it can last up to three weeks.As many as 100 to 1,000 males will compete to mate with a single female, sometimes surrounding her before she can fully emerge from her den. The males wrap around the female, becoming a living ball that can grow to be two feet high. The constant writhing of the snakes can even propel the ball over rocks and tree roots.
In some cases, the size of the snake ball will crush the female to death. However, this does not always deter the males, who may continue to mate with her.
A female will normally mate with only one male in the ball; once a male has successfully copulated with her, he releases a pheromone that temporarily makes all other males in the ball impotent. When the female selects her partner, the ball unravels and the unsuccessful males go in search of another female.
Since it is difficult for snakes to determine the gender of their potential partner, males detect the female by using their flicking tongues to sense the female's pheromones, which stimulate the males to mate. The male rubs his chin against the grain of the female's scales to squeeze out her pheromones. It is believed that the male can also determine the position of the female by detecting the direction of her pheromones and then aligning himself with her body accordingly.
One interesting phenomenon that is still not completely understood is that of the "she-male" snake-a male that gives off female pheromones when it emerges from the ground. One theory is that weaker male snakes emerging from the cold ground may do this so that other males will surround them in a ball to warm them up and protect them from predators. Studies have shown that "she-males" in this situation will return to being normal males after about three hours. Another theory is that "she-males" use their pheromones to confuse other males, who will try to mate with the "she-male' rather than vying for the true female.
Marlowe Shaeffer was the production editor for Twisted Network Programming Essentials . Nancy Kotary was the copyeditor, and Sada Preisch was the proofreader. Marlowe Shaeffer and Claire Cloutier provided quality control. Ellen Troutman Zaig wrote the index.
Karen Montgomery designed the cover of this book, based on a series design by Edie Freedman. The cover image is a 19th-century engraving from the Dover Pictorial Archive. Karen Montgomery produced the cover layout with Adobe InDesign CS using Adobe's ITC Garamond font.
David Futato designed the interior layout. This book was converted by Keith Fahlgren to FrameMaker 5.5.6. The text font is Linotype Birka; the heading font is Adobe Myriad Condensed; and the code font is LucasFont's TheSans Mono Condensed. The illustrations that appear in the book were produced by Robert Romano, Jessamyn Read, and Lesley Borash using Macromedia FreeHand MX and Adobe Photoshop CS. The tip and warning icons were drawn by Christopher Bing. This colophon was written by Jansen Fernald.The production editors for Book Title, eMatter Edition were Ellie Cutler and Jeff Liggett. Linda Walsh was the product manager. Kathleen Wilson provided design support. Lenny Muellner, Mike Sierra, Erik Ray, and Benn Salter provided technical support. This eMatter Edition was produced with FrameMaker 5.5.6.
Comments about oreilly Twisted Network Programming Essentials:
When Twisted (http://www.twistedmatrix.com) started to explode onto the scene, I was really intrigued by its varied capabilities and asynchronous model, but I was turned off by the then-scant documentation and the webapp framework transition that was just beginning (Woven was deprecated and Nevow was too new for any sort of coherent explanation). I just didn't have time to wrap my head around it, and so Twisted fell off my radar screen for a while. Eventually, I saw that a book was on the way, and I was excited to jump back in with it as my guide.
Network Programming Essentials (http://www.oreilly.com/catalog/twistedadn/) is not an exhaustive reference to Twisted, nor does it even pretend to be. Rather, it's a pretty friendly, task-oriented exploration, providing examples of common tasks and insight into the key concepts and design patterns that are essential to grokking Twisted. Each chapter focuses on a particular topic, and they're arranged to build upon each other nicely. Sections within each chapter are broken down into a practical, easily digested structure--we're introduced to the task at hand, then the "How do I do that?" and "How does it work?" bits clearly and plainly walk us through an example solution and dissect its inner workings. At 202 pages of actual text, its eleven chapters make for a comfortable chapter-per-evening of reading and play. It's well worth either keying in or downloading the example code to see Twisted in action.
Covered topics include installing Twisted, the essential Twisted concepts; HTTP clients and servers; RPC; authentication; mail clients and servers (POP and IMAP); NNTP clients and servers; fun with SSH; and some practical, non-glamorous things like running your app as a proper daemon, adding administrative interfaces, and logging. You'll monitor download progress, make a simple blog, build an IMAP server, and more. You'll chain protocols together to make an email interface to Google. You'll be impressed by the power and cleanliness of Twisted's authentication model, and you'll have fun getting and using references to remote Python objects with Perspective Broker. There's also a pretty good explanation of REST (http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm) ,
and plenty of links to useful reading.
All is unfortunately not shiny and delicious, though. I encountered what I consider quite a few programming errors in the example code, as well as several places where the explanatory text doesn't quite jive with the example. These errors are all fairly minor, and are probably artifacts of the evolution of the text and examples, but the frequency with which they crop up suggested that either no one had run the code before approving it for printing, or that errors were deliberately introduced to see if the reader is paying attention. As someone with a professional investment in web applications and frameworks, I was disappointed not to see any investigation of Nevow (not stable enough at the time of writing to be included, alas). The SSH chapter mentions but does not discuss or dive into the file transfer and connection tunneling concepts. I was also let down by the strict focus on programs that only used the basic Twisted reactor for managing events--the challenge of integrating Twisted's powerful capabilities into an existing event-driven program (eg, any GUI app) is entirely omitted. Furthermore, the book ends somewhat suddenly; I would have welcomed a "Great! What now?" sort of wrap-up that would provide a guidepost to more advanced topics.
These warts are quite forgiveable, however, and will hopefully be corrected in a future revision. The book is clean, friendly, and clear, and provides a nice entry into the world of Twisted. We are neither talked down to, nor beaten into submission by overly dense, inscrutable prose. For this printing, keep the errata handy to quickly resolve any issues with the example code (and submit anything new that you find). While the topics might be considered limited, it's clear that what's here is the tip of the iceberg; you can use these familiar topics to try to sell your boss on Twisted, and then your imagination is the only limit to what you can do. Since my initial experience with Twisted, the core
documentation (http://twistedmatrix.com/projects/core/documentation/howto/index.html) has improved immensely, but it's even stronger if you're already familiar with what's presented here; start with this book, then dive on into the online docs, and you'll be a Twisted guru in no time.