diff --git a/.gitignore b/.gitignore index c2c9f3382..e55c81f22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ Python/__pycache__/WebSiteHandler\.cpython-37\.pyc \.idea/ + +*.pyc + +Python/app/__pycache__/ + +Python/app/handlers/__pycache__/ diff --git a/Python/WebSiteHandler.py b/Python/WebSiteHandler.py deleted file mode 100644 index b0c12c0f3..000000000 --- a/Python/WebSiteHandler.py +++ /dev/null @@ -1,35 +0,0 @@ -import http.server, socketserver, os -import websockets, asyncio -import multiprocessing - -HttpServerPort = 80 -SocketServerPort = 8765 - - -def run_server(): - web_dir = os.path.join(os.path.dirname(__file__), '../Site') - os.chdir(web_dir) - handler = http.server.SimpleHTTPRequestHandler - with socketserver.TCPServer(("", HttpServerPort), handler) as httpd: - print('server has started') - httpd.serve_forever() - - -async def web_socket_handler(socket, path): - print('test') - data = await socket.recv() - print(data) - - -def test(): - print('socket started') - socket = websockets.serve(web_socket_handler, 'ws://localhost', SocketServerPort) - print(socket) - - -def run_all(): - html_process = multiprocessing.Process(target=run_server) - socket_process = multiprocessing.Process(target=test) - html_process.start() - socket_process.start() - diff --git a/Python/app/Chameleon_Vision_App.py b/Python/app/Chameleon_Vision_App.py index 9f4825e65..98091aea4 100644 --- a/Python/app/Chameleon_Vision_App.py +++ b/Python/app/Chameleon_Vision_App.py @@ -3,6 +3,7 @@ import tornado.websocket import os from handlers.MainHandler import MainHandler +from handlers.SocketHandler import ChameleonWebSocket from tornado.options import define define("port", default=8888, help="run on the given port", type=int) @@ -11,6 +12,7 @@ define("port", default=8888, help="run on the given port", type=int) class ChameleonApplication(tornado.web.Application): def __init__(self): handlers = [(r"/", MainHandler), + (r"/websocket", ChameleonWebSocket), (r"/CSS/(.*)", tornado.web.StaticFileHandler, {'path': os.path.join(os.path.dirname(__file__), "../../Site/CSS")}), (r"/JS/(.*)", tornado.web.StaticFileHandler, {'path': os.path.join(os.path.dirname(__file__), "../../Site/JS")})] diff --git a/Python/app/__pycache__/Chameleon_Vision_App.cpython-37.pyc b/Python/app/__pycache__/Chameleon_Vision_App.cpython-37.pyc deleted file mode 100644 index 5a3d78b99..000000000 Binary files a/Python/app/__pycache__/Chameleon_Vision_App.cpython-37.pyc and /dev/null differ diff --git a/Python/app/__pycache__/__init__.cpython-37.pyc b/Python/app/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 38d5bf51e..000000000 Binary files a/Python/app/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/Python/app/handlers/SocketHandler.py b/Python/app/handlers/SocketHandler.py new file mode 100644 index 000000000..a2e7a84f9 --- /dev/null +++ b/Python/app/handlers/SocketHandler.py @@ -0,0 +1,12 @@ +import tornado.websocket + +class ChameleonWebSocket(tornado.websocket.WebSocketHandler): + def open(self): + print("WebSocke opend") + + def on_message(self, message): + print(message) + self.write_message("why the fuck did you send a messege") + def on_close(self): + print("websocket closed") + diff --git a/Python/app/handlers/__pycache__/MainHandler.cpython-37.pyc b/Python/app/handlers/__pycache__/MainHandler.cpython-37.pyc deleted file mode 100644 index 025cebc76..000000000 Binary files a/Python/app/handlers/__pycache__/MainHandler.cpython-37.pyc and /dev/null differ diff --git a/Python/app/handlers/__pycache__/__init__.cpython-37.pyc b/Python/app/handlers/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index c30c4aba9..000000000 Binary files a/Python/app/handlers/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/Site/Index.html b/Site/Index.html index 47a91b4e7..653faa43e 100644 --- a/Site/Index.html +++ b/Site/Index.html @@ -15,5 +15,14 @@ 3D + \ No newline at end of file