Member-only story
Build a Simple Web Server With Python
Create and run a simple server you can customize to your needs
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.