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
Author(s): Brandon Rhodes; John Goerzen
Series: Expert's voice in open source
Edition: 2ed.
Publisher: Apress
Year: 2010
Language: English
Pages: 370
Prelim......Page 1
Contents at a Glance......Page 6
Contents......Page 7
About the Authors......Page 17
About the Technical Reviewer......Page 18
Acknowledgements......Page 19
Introduction......Page 20
The Building Blocks: Stacks and Libraries......Page 23
Application Layers......Page 26
Speaking a Protocol......Page 27
A Raw Network Conversation......Page 28
Turtles All the Way Down......Page 30
The Internet Protocol......Page 31
IP Addresses......Page 32
Routing......Page 33
Packet Fragmentation......Page 35
Learning More About IP......Page 36
UDP......Page 37
Addresses and Port Numbers......Page 38
Port Number Ranges......Page 39
Sockets......Page 41
Unreliability, Backoff, Blocking, Timeouts......Page 44
Connecting UDP Sockets......Page 47
Request IDs: A Good Idea......Page 49
Binding to Interfaces......Page 50
UDP Fragmentation......Page 52
Socket Options......Page 53
Broadcast......Page 54
When to Use UDP......Page 55
Summary......Page 56
How TCP Works......Page 57
When to Use TCP......Page 58
What TCP Sockets Mean......Page 59
A Simple TCP Client and Server......Page 60
One Socket per Conversation......Page 63
Address Already in Use......Page 64
Binding to Interfaces......Page 65
Deadlock......Page 66
Closed Connections, Half-Open Connections......Page 70
Summary......Page 71
Hostnames and Domain Names......Page 73
Socket Names......Page 74
Five Socket Coordinates......Page 75
IPv6......Page 76
Modern Address Resolution......Page 77
Asking getaddrinfo() About Services......Page 78
Asking getaddrinfo() for Pretty Hostnames......Page 79
Other getaddrinfo() Flags......Page 80
Primitive Name Service Routines......Page 81
Using getsockaddr() in Your Own Code......Page 82
Better Living Through Paranoia......Page 83
A Sketch of How DNS Works......Page 85
Why Not to Use DNS......Page 87
Why to Use DNS......Page 88
Resolving Mail Domains......Page 90
Summary......Page 92
Text and Encodings......Page 93
Network Byte Order......Page 95
Framing and Quoting......Page 97
Pickles and Self-Delimiting Formats......Page 101
XML, JSON, Etc.......Page 102
Compression......Page 103
Network Exceptions......Page 104
Handling Exceptions......Page 105
Summary......Page 107
Computer Security......Page 109
IP Access Rules......Page 110
Cleartext on the Network......Page 112
TLS Encrypts Your Conversations......Page 114
TLS Verifies Identities......Page 115
Supporting TLS in Python......Page 116
The Standard SSL Module......Page 117
Summary......Page 120
Daemons and Logging......Page 121
Our Example: Sir Launcelot......Page 122
An Elementary Client......Page 124
The Waiting Game......Page 125
Running a Benchmark......Page 128
Event-Driven Servers......Page 131
Poll vs. Select......Page 134
The Semantics of Non-blocking......Page 135
Twisted Python......Page 136
Threading and Multi-processing......Page 139
Threading and Multi-processing Frameworks......Page 142
Process and Thread Coordination......Page 144
Running Inside inetd......Page 145
Summary......Page 146
Caches, Message Queues, and Map-Reduce......Page 147
Using Memcached......Page 148
Memcached and Sharding......Page 150
Message Queues......Page 152
Using Message Queues from Python......Page 153
How Message Queues Change Programming......Page 155
Map-Reduce......Page 156
Summary......Page 158
HTTP......Page 159
URL Anatomy......Page 160
Instrumenting urllib2......Page 163
The GET Method......Page 164
Codes, Errors, and Redirection......Page 166
Payloads and Persistent Connections......Page 169
POST And Forms......Page 170
Successful Form POSTs Should Always Redirect......Page 172
REST And More HTTP Methods......Page 173
Identifying User Agents and Web Servers......Page 174
Content Type Negotiation......Page 175
Compression......Page 176
HTTP Caching......Page 177
HTTPS Encryption......Page 178
HTTP Authentication......Page 179
Cookies......Page 180
Cross-Site Scripting Attacks......Page 182
Summary......Page 183
Fetching Web Pages......Page 185
Downloading Pages Through Form Submission......Page 186
The Structure of Web Pages......Page 189
Three Axes......Page 190
Diving into an HTML Document......Page 191
Selectors......Page 195
Summary......Page 199
Web Applications......Page 201
Two Tiers......Page 202
Choosing a Web Server......Page 204
WSGI......Page 205
WSGI Middleware......Page 207
Python Web Frameworks......Page 209
URL Dispatch Techniques......Page 211
Templates......Page 212
Final Considerations......Page 213
Pure-Python Web Servers......Page 214
CGI......Page 215
mod_python......Page 216
Summary......Page 217
E-mail Composition and Decoding......Page 219
E-mail Messages......Page 220
Composing Traditional Messages......Page 222
Parsing Traditional Messages......Page 224
Parsing Dates......Page 225
Understanding MIME......Page 227
Composing MIME Attachments......Page 228
MIME Alternative Parts......Page 230
Composing Non-English Headers......Page 232
Composing Nested Multiparts......Page 233
Parsing MIME Messages......Page 235
Decoding Headers......Page 237
Summary......Page 238
E-mail Clients, Webmail Services......Page 239
Sending E-Mail......Page 243
Headers and the Envelope Recipient......Page 244
Multiple Hops......Page 245
Introducing the SMTP Library......Page 246
Error Handling and Conversation Debugging......Page 247
Getting Information from EHLO......Page 250
Using Secure Sockets Layer and Transport Layer Security......Page 252
Authenticated SMTP......Page 254
SMTP Tips......Page 255
Summary......Page 256
Connecting and Authenticating......Page 257
Obtaining Mailbox Information......Page 260
Downloading and Deleting Messages......Page 261
Summary......Page 263
IMAP......Page 265
Understanding IMAP in Python......Page 266
IMAPClient......Page 268
Message Numbers vs. UIDs......Page 270
Summary Information......Page 271
Downloading an Entire Mailbox......Page 272
Downloading Messages Individually......Page 274
Flagging and Deleting Messages......Page 279
Deleting Messages......Page 280
Searching......Page 281
Manipulating Folders and Messages......Page 282
Summary......Page 283
Command-Line Automation......Page 285
Command-Line Expansion and Quoting......Page 287
Unix Has No Special Characters......Page 288
Quoting Characters for Protection......Page 290
The Terrible Windows Command Line......Page 291
Things Are Different in a Terminal......Page 292
Terminals Do Buffering......Page 295
Telnet......Page 296
SSH: The Secure Shell......Page 300
An Overview of SSH......Page 301
SSH Host Keys......Page 302
SSH Authentication......Page 304
Shell Sessions and Individual Commands......Page 305
SFTP: File Transfer Over SSH......Page 308
Other Features......Page 311
Summary......Page 312
What to Use Instead of FTP......Page 313
Communication Channels......Page 314
Using FTP in Python......Page 315
ASCII and Binary Files......Page 316
Advanced Binary Downloading......Page 317
Uploading Data......Page 319
Advanced Binary Uploading......Page 320
Handling Errors......Page 321
Detecting Directories and Recursive Download......Page 323
Creating Directories, Deleting Things......Page 324
Summary......Page 325
RPC......Page 327
Features of RPC......Page 328
XML-RPC......Page 329
JSON-RPC......Page 335
Self-documenting Data......Page 337
Talking About Objects: Pyro and RPyC......Page 338
An RPyC Example......Page 339
RPC, Web Frameworks, Message Queues......Page 341
Binary Options: Thrift and Protocol Buffers......Page 342
Summary......Page 343
Index......Page 345