: Brandon Rhodes, John Goerzen
: Foundations of Python Network Programming
: Apress
: 9781430258551
: 3
: CHF 59.50
:
: Allgemeines, Lexika
: English
: 369
: Wasserzeichen/DRM
: PC/MAC/eReader/Tablet
: PDF

Foundat ons of Python Network Programming,Third Edition, covers all of the classic topics found in the second edition of this book, including network protocols, network data and errors, email, server architecture, and HTTP and web applications, plus updates for Python 3.

Some of the new topics in this edition include:

• Extensive coverage of the updated SSL support in Python 3

• How to write your own asynchronous I/O loop.

• An overview of the 'asyncio' framework that comes with Python 3.4.

• How the Flask web framework connects URLs to your Python code.

• How cross-site scripting and cross-site request forgery can be used to attack your web site, and how to protect against them.

• How a full-stack web framework like Django can automate the round trip from your database to the screen and back.

If you're a Python programmer who needs a deep understanding of how to use Python for network-related tasks and applications, this is the book for you. From web application developers, to systems integrators, to system administrators—this book has everything that you need to know.



Brandon Rhodes is a consulting programmer who also teaches the Python language professionally for organizations that are adding the language to their tool set. He has spoken at PyOhio; at PyGotham; at national PyCon conferences in Canada, Ireland, and Poland; and at Django conferences in Portland, Wales, and Warsaw, where he was delighted at the creativity of the organizers, who rented a circus tent for the occasion. He will chair the flagship PyCon North America conference in Portland in 2016–2017. Brandon is interested in how ideas like the Clean Architecture can help programmers organize code more effectively and in what we can learn from writers in other fields about offering kind and actionable critiques of each other’s work. He currently lives in tiny Bluffton, Ohio, with his wife Jackie and their two cats.
Contents at a Glance3
Contents358
About the Author367
About the Technical Reviewers368
Acknowledgments369
Introduction5
Chapter 1: Introduction to Client-Server Networking9
The Building Blocks: Stacks and Libraries9
Application Layers12
Speaking a Protocol13
A Raw Network Conversation14
Turtles All the Way Down17
Encoding and Decoding18
The Internet Protocol19
IP Addresses20
Routing21
Packet Fragmentation22
Learning More About IP23
Summary24
Chapter 2: UDP25
Port Numbers26
Sockets27
Promiscuous Clients and Unwelcome Replies31
Unreliability, Backoff, Blocking, and Timeouts32
Connecting UDP Sockets36
Request IDs: A Good Idea37
Binding to Interfaces38
UDP Fragmentation40
Socket Options41
Broadcast42
When to Use UDP44
Summary44
Chapter 3: TCP46
How TCP Works46
When to Use TCP47
What TCP Sockets Mean48
A Simple TCP Client and Server49
One Socket per Conversation52
Address Already in Use53
Binding to Interfaces54
Deadlock55
Closed Connections, Half-Open Connections60
Using TCP Streams Like Files61
Summary61
Chapter 4: Socket Names and DNS63
Hostnames and Sockets63
Five Socket Coordinates64
IPv665
Modern Address Resolution66
Using getaddrinfo() to Bind Your Server to a Port67
Using getaddrinfo() to Connect to a Service68
Asking getaddrinfo() for a Canonical Hostname69
Other getaddrinfo() Flags70
Primitive Name Service Routines71
Using getsockaddr() in Your Own Code71
The DNS Protocol73
Why Not to Use Raw DNS75
Making a DNS Query from Python75
Resolving Mail Domains77
Summary79
Chapter 5: Network Data and Network Errors80
Bytes and Strings80
Character Strings81
Binary Numbers and Network Byte Order84
Framing and Quoting86
Pickles and Self-delimiting Formats91
XML and JSON91
Compression92
Network Exceptions93
Raising More Specific Exceptions95
Catching and Reporting Network Exceptions96
Summary97
Chapter 6: TLS/SSL98
What TLS Fails to Protect98
What Could Possibly Go Wrong?99
Generating Certificates100
Offloading TLS103
Python 3.4 Default Contexts104
Variations on Socket Wrapping108
Hand-Picked Ciphers and Perfect Forward Security109
Protocol Support for TLS111
Learning Details112
Summary118
Chapter 7: Server Architecture119
A Few Words About Deployment119
A Simple Protocol121
A Single-Threaded Server124
Threaded and Multiprocess Servers127
The Legacy SocketServer Framework128
Async Servers129
Callback-Style asyncio132
Coroutine-Style asyncio134
The Legacy Module asyncore135
The Best of Both Worlds137
Running Under inetd137
Summary139
Chapter 8: Caches and Message Queues140
Using Memcached140
Hashing and Sharding143
Message Queues145
Using Message Queues from Python147
Summary151
Chapter 9: HTTP Clients153
Python Client Libraries153
Ports, Encryption, and Framing155
Methods156
Paths and Hosts157
Status Codes158
Caching and Validation160
Content Encoding163
Content Negotiation163
Content Type165
HTTP Authentication165
Cookies167
Connections, Keep-Alive, and httplib168
Summary169
Chapter 10: HTTP Servers170
WSGI170
Asynchronous Server- Frameworks172
Forward and Reverse Proxies172
Four Architectures173
Running Python Under Apache175
The Rise of Pure-Python HTTP Servers175
The Benefits of Reverse Proxies175
Platforms as a Service176
GET and POST Patterns and the Question of REST177
WSGI Without a Framework179
Summary183
Chapter 11: The World Wide Web184
Hypermedia and URLs184
Parsing and Building URLs185
Relative URLs187
The Hypertext Markup Language189
Reading and Writing to a Database192
A Terrible Web Application (in Flask)193
The Dance of Forms and HTTP Methods198