Simple HTTP server python 3

Simple HTTP server python 3 tutorial: The HTTP request will travel to the Google computer that has the webserver running on it. The interception of webserver and handling is done with HTML of the Google home page. The browser renders the HTML on the screen and what you see on your screen. The machine will receive an HTTP request that has a software process called a web server running on it. This web server is responsible for intercepting requests and handles them. An HTTP web server is a process which is running on your machine and does two things,

  1. It listens for incoming HTTP requests on a specific TCP socket address.
  2. Also handles the request and send a response back to the user.

After opening the Chrome browser and we type google.com in the address bar, and then we get the Google home page.
When you type google.com on your browser the browser will create a network message called as HTTP request.
The HTTP Request will travel to the Google computer that has the webserver running on it.
The browser renders HTML on the screen and what you see on your screen.

Set up the HTTP server:-

 Navigating to the directory,
$cd/home/somedir
Type,
$python-m SimpleHTTPServer

If we use the windows operating system then we go to a folder or directory that you want to share.
Then find the option to open a command prompt in that directory.
After that just click on that and then open command prompt there.
 If you are using Ubuntu then right click into that directory and open terminal and execute the command,
Python-mSimpleHTTPServer9000

Example:-

From BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
PORT_NUMBER=8080
Class myHandler (BaseHTTPRequesrHandler):
Def do_GET (self):
Self.send_respons (200)
Self.send_header (‘content-type’,’text/html’)
Self.end_headers ()
Self.wfile.write (“Hello World!”)
Return
Try:
Server=HTTPServer ((“, PORT_NUMBER), myHandler)
Print’started httpserver on port’, PORT_NUMBER
Server.serve_forever ()
Except KeyboardInterrupt:
Print’^C recived, shutting down the web server’
Server.socket.close ()

Run:-


Debarm: ~/playground/python/httpserver#python example 1.py
We open your web browser on the URL as http://fox_ip_address:8080.
Output:-
"Hello World!”Appears on browser
Started httpserver on port 8080
10.55.98.7—[30jan/2012 15:40:52]”GET/HTTP/1.1”200-
10.55.98.7—[30jan/2012 15:40:52]”GET/favicon.icon HTTP/1.1”200-

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India