Skip to content

Instantly share code, notes, and snippets.

@adarsh0806
Created February 5, 2016 21:35
Show Gist options
  • Select an option

  • Save adarsh0806/e836730cebe920f68f54 to your computer and use it in GitHub Desktop.

Select an option

Save adarsh0806/e836730cebe920f68f54 to your computer and use it in GitHub Desktop.

Revisions

  1. adarsh0806 created this gist Feb 5, 2016.
    31 changes: 31 additions & 0 deletions simpleserver.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/python
    from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer

    PORT_NUMBER = 8080

    #This class will handles any incoming request from
    #the browser
    class myHandler(BaseHTTPRequestHandler):

    #Handler for the GET requests
    def do_GET(self):
    self.send_response(200)
    self.send_header('Content-type','text/html')
    self.end_headers()
    # Send the html message
    self.wfile.write("Hello World !")
    return

    try:
    #Create a web server and define the handler to manage the
    #incoming request
    server = HTTPServer(('', PORT_NUMBER), myHandler)
    print 'Started httpserver on port ' , PORT_NUMBER

    #Wait forever for incoming htto requests
    server.serve_forever()

    except KeyboardInterrupt:
    print '^C received, shutting down the web server'
    server.socket.close()