Book Image

Learning Python Network Programming

By : Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington
Book Image

Learning Python Network Programming

By: Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington

Overview of this book

Table of Contents (17 chapters)
Learning Python Network Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

What's in a web server?


To understand how we can employ Python in responding to HTTP requests, we need to know a bit about what typically needs to occur in order to respond to a request, and what tools and patterns already exist to do this.

A basic HTTP request and response might look like this:

Here our web client sends an HTTP request to a server, where a web server program interprets the request, creates a suitable HTTP response, and sends it back. In this case, the response body is simply the contents of an HTML file read from, with the response headers added by the web server program.

The web server is responsible for the entire process of responding to the client's request. The basic steps it needs to perform are:

First the web server program needs to accept the TCP connection attempt by the client. It then receives the HTTP request from the client over the TCP connection. The server needs to keep the TCP connection open while it generates the HTTP response, and it uses the connection...