-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
36 lines (34 loc) · 1.13 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from UDPHandler import UDPHandler
from WebServer import MakeHandlerClassFromArgv
from http.server import HTTPServer
from WaypointDB import WaypointDB
from WaypointDB import Waypoint
import _thread
import os
import ssl
waypointsDB = WaypointDB()
handler = UDPHandler(5555,waypointsDB)
try:
# waypointsDB.readFromFile()
# print(len(waypointsDB.waypoints))
handler.init_socket()
handler.read_from_file()
handler.start()
print("Ready to receive ACARS Messages\n")
httpd = HTTPServer(('',8888),MakeHandlerClassFromArgv(handler))
# Check if we have certificates
if os.path.exists("./certs"):
if len(os.listdir('./certs')) != 0:
print("Certificates found, using HTTPS")
httpd.socket = ssl.wrap_socket (httpd.socket,
keyfile='certs/privkey.pem',
certfile='certs/fullchain.pem', server_side=True)
else:
print("No certificates, using HTTP")
else:
print("No certificates, using HTTP")
httpd.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down the web server')
handler.stop()
handler.join()