|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
|
|
|
from socketserver import ThreadingMixIn
|
|
|
|
|
import threading
|
|
|
|
|
import json
|
|
|
|
|
from threading import Thread
|
|
|
|
|
from . import Processor
|
|
|
|
@ -11,27 +13,6 @@ import os #for path operations
|
|
|
|
|
from http import cookies
|
|
|
|
|
global mGlobalDict
|
|
|
|
|
from . import ServerSettings
|
|
|
|
|
#inGlobalDict
|
|
|
|
|
# "JSONConfigurationDict":<JSON>
|
|
|
|
|
class RobotDaemonServer(Thread):
|
|
|
|
|
def __init__(self,name,inGlobalDict):
|
|
|
|
|
Thread.__init__(self)
|
|
|
|
|
self.name = name
|
|
|
|
|
# Update the global dict
|
|
|
|
|
ServerSettings.SettingsUpdate(mGlobalDict)
|
|
|
|
|
def run(self):
|
|
|
|
|
inServerAddress="";
|
|
|
|
|
inPort = mGlobalDict["Server"]["ListenPort"];
|
|
|
|
|
# Server settings
|
|
|
|
|
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
|
|
|
|
|
server_address = (inServerAddress, inPort)
|
|
|
|
|
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
|
|
|
|
|
# Logging
|
|
|
|
|
mGlobalDict["Logger"].info(f"Server init. Listen URL: {inServerAddress}, Listen port: {inPort}")
|
|
|
|
|
# Запуск адреса в браузере
|
|
|
|
|
os.system("explorer http://127.0.0.1:8081")
|
|
|
|
|
httpd.serve_forever()
|
|
|
|
|
|
|
|
|
|
#Authenticate function ()
|
|
|
|
|
# return dict
|
|
|
|
|
# {
|
|
|
|
@ -417,3 +398,36 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
# Send headers
|
|
|
|
|
self.end_headers()
|
|
|
|
|
return
|
|
|
|
|
#Logging
|
|
|
|
|
#!Turn it on to stop print in console
|
|
|
|
|
#def log_message(self, format, *args):
|
|
|
|
|
# return
|
|
|
|
|
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
|
|
|
|
|
"""Handle requests in a separate thread."""
|
|
|
|
|
def finish_request(self, request, client_address):
|
|
|
|
|
request.settimeout(30)
|
|
|
|
|
# "super" can not be used because BaseServer is not created from object
|
|
|
|
|
HTTPServer.finish_request(self, request, client_address)
|
|
|
|
|
#inGlobalDict
|
|
|
|
|
# "JSONConfigurationDict":<JSON>
|
|
|
|
|
class RobotDaemonServer(Thread):
|
|
|
|
|
def __init__(self,name,inGlobalDict):
|
|
|
|
|
Thread.__init__(self)
|
|
|
|
|
self.name = name
|
|
|
|
|
# Update the global dict
|
|
|
|
|
ServerSettings.SettingsUpdate(mGlobalDict)
|
|
|
|
|
def run(self):
|
|
|
|
|
inServerAddress="";
|
|
|
|
|
inPort = mGlobalDict["Server"]["ListenPort"];
|
|
|
|
|
# Server settings
|
|
|
|
|
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
|
|
|
|
|
server_address = (inServerAddress, inPort)
|
|
|
|
|
#httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
|
|
|
|
|
# Logging
|
|
|
|
|
mGlobalDict["Logger"].info(f"Server init. Listen URL: {inServerAddress}, Listen port: {inPort}")
|
|
|
|
|
# Запуск адреса в браузере
|
|
|
|
|
os.system("explorer http://127.0.0.1:8081")
|
|
|
|
|
#httpd.serve_forever()
|
|
|
|
|
httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler)
|
|
|
|
|
#print('Starting server, use <Ctrl-C> to stop')
|
|
|
|
|
httpd.serve_forever()
|
|
|
|
|