Better Programming

Advice for programmers.

Follow publication

Member-only story

Build a Simple Web Server With Python

Pavel Ilin
Better Programming
Published in
4 min readSep 4, 2020

Photo by Johannes Groll on Unsplash.

Web servers are all around us. Every application, every framework uses a web server. It might sound fancy, but every web server does three things: It listens for HTTP requests, handles those requests, and sends responses back to the user. Let’s try to build our own server with Python.

Nature of the HTTP Server

When you try to open Medium, your browser will create a network message in the form of an HTTP request. Requests will travel all the way through the internet to a computer where Medium has a running server that will handle this request by responding with HTML of the Medium home page. When your browser receives a response, it will render HTML so we can see the web page of the rendered error message in case something goes wrong.

Every interaction with the web page will send a new request and the server will respond with new HTML.

Let’s see how the request can get to the server.

Importance of Listening

To get the destination, each HTTP message contains the destination TCP address. A TCP address is an IP address and port number.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Pavel Ilin
Pavel Ilin

Written by Pavel Ilin

Software Engineer, Researcher and Transhumanist.

Write a response