#!/usr/bin/env python3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import sys
import time
import datetime
from http.server import BaseHTTPRequestHandler, HTTPServer
import urllib.request
# WEB SERVER parameters
hostName = "0.0.0.0"
hostPort = 9000
prog = 0;
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
global droid
global myServer
# referer = self.headers.get('Referer')
get_url = self.path
print("GET:" + get_url)
if get_url == "/" or get_url == "/index.htm":
self.send_html_headers()
self.send("""
""")
return
elif get_url == "/tab1.htm":
global prog;
self.send_html_headers()
prog += 1;
self.send("Contatore: " + str(prog) + " |
")
return
def send_html_headers(self):
self.send_response(200)
self.send_header("Content-type", "text/html;charset=UTF-8")
self.end_headers()
def send_redirect_header(self, newpage):
self.send_response(301)
if not newpage.startswith("http") and not newpage.startswith("about"):
newpage = "http://" + self.headers.get('Host') + newpage
self.send_header("Location", newpage)
self.end_headers()
def send(self, message):
self.wfile.write(bytes(message, "utf-8"))
#start web server
myServer = HTTPServer((hostName, hostPort), MyServer)
print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort))
#process browser requests
try:
myServer.serve_forever()
except Exception as err:
print ('client exit request, shutting down the web server')
#stop web server
try:
myServer.server_close()
print(time.asctime(), "Server Stops - %s:%s" % (hostName, hostPort))
except:
pass