Network Programming Python - HTTP Server Last Updated : 24 Oct, 2020 Comments Improve Suggest changes Like Article Like Report HTTP Web Server is simply a process which runs on a machine and listens for incoming HTTP Requests by a specific IP and Port number, and then sends back a response for the request. Python has a built-in webserver provided by its standard library, can be called for simple client-server communication. The http.server and socketserver are the two main functions used to create a web server. Port number can be defined manually in the program which is used to access the webserver. This web server is functional for many types of file formats, but it is not fully featured. A simple static HTML files can easily be parsed and served by responding with the required response code. A basic implementation of python HTTP web server is given below : Sample HTML File : <html>   <head>     <title>Python HTTP Server</title>   </head>   <body>     <h1>Simple HTTP Server</h1>     <p>Congratulations! The HTTP Server is working! Welcome to GeeksForGeeks</p>   </body> </html> Python3 # Import libraries import http.server import socketserver # Defining PORT number PORT = 8080 # Creating handle Handler = http.server.SimpleHTTPRequestHandler # Creating TCPServer http = socketserver.TCPServer(("", PORT), Handler) # Getting logs print("serving at port", PORT) http.serve_forever() Output: serving at port 8080 127.0.0.1 - - [17/Oct/2020 00:31:27] "GET / HTTP/1.1" 200 - Execute the above program in the directory where the HTML File is saved. After creating the Web Server open the Web Browser and type http://localhost:8080/ in the URL. Here, SimpleHTTPRequestHandler is used to create a custom handler. TCPServer tells the server to send and receive messages. To invoke TCPServer, two arguments are required the TCP Address i.e. IP and PORT, and second is the handler. TCP Address is a tuple consisting of IP address and PORT number. Serve_forever() is a function of the TCPServer instance that starts the server and listens and responds to the incoming requests. The localhost is the host machine(in our case the system we are using), used to access the network services using the loopback network interface. If the python program is to be used only as localhost serving, the below program is used for that purpose : Python3 # Import libraries import sys import http.server import socketserver # Creating handle HandlerClass = http.server.SimpleHTTPRequestHandler # Creating Server ServerClass = http.server.HTTPServer # Defining protocol Protocol = "HTTP/1.0" # Setting TCP Address if sys.argv[1:]: port = int(sys.argv[1]) else: port = 8000 server_address = ('127.0.0.1', port) # invoking server HandlerClass.protocol_version = Protocol http = ServerClass(server_address, HandlerClass) # Getting logs sa = http.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "...") http.serve_forever() Output: Comment More infoAdvertise with us Next Article Network Programming Python - HTTP Server J jeeteshgavande30 Follow Improve Article Tags : Technical Scripter Python Programming Language Technical Scripter 2020 Python-Networking +1 More Practice Tags : python Similar Reads Network Programming Python - HTTP Requests HTTP stands for HyperText Transfer Protocol, which works on the client-server machine. In most cases, the web browser acts as the client, and the computer which hosts the website acts as a server. Python provides the requests module to play with HTTP requests. The requests module plays a major role 2 min read Network Programming Python - HTTP Clients The request from the client in HTTP protocol reaches the server and fetches some data assuming it to be a valid request. This response from the server can be analyzed by using various methods provided by the requests module. Some of the ways below provide information about the response sent from the 2 min read Socket Programming in Python Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while the other socket reaches out to the other to form a connection. The server forms the listener socket while the client reaches out to the serv 6 min read CGI Programming in Python What is CGI? Common Gateway Interface (also known as CGI) is not a kind of language but just a specification(set of rules) that helps to establish a dynamic interaction between a web application and the browser (or the client application). The CGI programs make possible communication between client 5 min read Simple Calculator in Python Socket Programming In this article, we are going to know how to make a simple calculator in Python socket programming. Prerequisite: Socket Programming in Python. First, we will understand the basics of Python socket programming. Socket programming is used to set up a communication channel between two nodes on a netwo 4 min read Socket Programming with Multi-threading in Python Prerequisite : Socket Programming in Python, Multi-threading in PythonSocket Programming-> It helps us to connect a client to a server. Client is message sender and receiver and server is just a listener that works on data sent by client.What is a Thread? A thread is a light-weight process that d 3 min read Install Httpx using Python PIP When working on the internet or building websites, it's important to have good tools to ask for information. HTTPX is one of these tools, and a lot of people like it because it's fast, flexible, and has many features. This article will explain what HTTPX is and show you simple steps to put it on you 3 min read Python Tornado - Asynchronous Networking Traditional synchronous networking models often struggle to keep pace with the demands of modern applications. Enter Tornado-Asynchronous networking, a paradigm-shifting approach that leverages non-blocking I/O to create lightning-fast, highly scalable network applications. In this article, we will 4 min read Introduction to Bottle Web Framework - Python There are many frameworks in python which allows you to create webpage like bottle, flask, django. In this article you will learn how to create simple app bottle.Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no depende 2 min read Python Pyramid - Request Object Python has gained widespread popularity among developers in recent times. Numerous web-related frameworks are available in Python, such as Flask, Django, Pyramid, and FastAPI. Among these frameworks, Python Pyramid stands out as a robust web framework that offers flexibility and scalability for deve 4 min read Like