From 05305393a9107d7d17455a53452c78b523abeb9a Mon Sep 17 00:00:00 2001 From: ori agranat Date: Fri, 1 Mar 2019 21:59:49 +0200 Subject: [PATCH] web socket using tornado --- .gitignore | 6 +++ Python/WebSiteHandler.py | 35 ------------------ Python/app/Chameleon_Vision_App.py | 2 + .../Chameleon_Vision_App.cpython-37.pyc | Bin 1033 -> 0 bytes .../app/__pycache__/__init__.cpython-37.pyc | Bin 147 -> 0 bytes Python/app/handlers/SocketHandler.py | 12 ++++++ .../__pycache__/MainHandler.cpython-37.pyc | Bin 506 -> 0 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 156 -> 0 bytes Site/Index.html | 9 +++++ 9 files changed, 29 insertions(+), 35 deletions(-) delete mode 100644 Python/WebSiteHandler.py delete mode 100644 Python/app/__pycache__/Chameleon_Vision_App.cpython-37.pyc delete mode 100644 Python/app/__pycache__/__init__.cpython-37.pyc create mode 100644 Python/app/handlers/SocketHandler.py delete mode 100644 Python/app/handlers/__pycache__/MainHandler.cpython-37.pyc delete mode 100644 Python/app/handlers/__pycache__/__init__.cpython-37.pyc 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 5a3d78b99f59e6bb6b5033575a274c322969a90a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1033 zcmZWo&2H2%5VoD{Ci@3elpi6GR-6ceU2#PS0Tr|ts!A&XidHfq_I90mlVE#`x@u3Y zR4(Ni=#e+zS$yThEA+%TyW6gW6OU&+lkqp-IBz%TWjA6-@mJ z1Vao<6ys_oi`9!gu!;01wYY{|j3?`pAPz9%0rOdn)p^K*GasW(#6s3ML9D@X*2tR2 zUfg1MfTHGK$d0xnY+LUWk#8kAlU#vWXM7}bZvC=QM*Mz=(Cn6)=G`LinlbP0ihZ7U zoiFli0I|tb8tad_EUj-2N}jsB%i%2)eIFEF)e)0ZG{OusauUYgDe_V510K(=Z;X=( zm%PYdm!%YGVnmUrc#*+nYQS`>{tSX)gGPiAgENwO%rkyg`&qAKV8V0E{Bt7k$lE1H z*fjq0*3Jp5pW!27nx=J#j!D)Ou2eqhHaAPTlGaDUe5Zwv`pFp`+@>{_qa zhj$?W#Bl0@qmF{^A{&@OId?FWyQsBb^Wn!r?F~1D>F%f^mtHHX?&1{F0aofK?ZRoABU>ok#bPnFts7O+z; zC8g>P98!r0tJ_Y$>x4VI1yehkLtNQWJ8mub?g8D(`Qx>f9bKe*+^CM*UtdzzTlov- zO}oDQq$u4@)XH5w>xtYbSGR4gR9GE+g>kMqgf@IJFY=|k$l84vVt7a!x5*9fABJ-k A4FCWD diff --git a/Python/app/__pycache__/__init__.cpython-37.pyc b/Python/app/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 38d5bf51e8ea598d4809f040c7580041b3916d89..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 147 zcmZ?b<>g`kg0GpCF(CReh=2h`Aj1KOi&=m~3PUi1CZpd`(0P?VpQnp{#G+Xgd^nu 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 025cebc766f8ed5945d9023e832a5ee0c2a8e352..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 506 zcmYjN%}xR_5N@~2k05yQ0l0FI2QbDEiGhoRXrjqxlV+vWU0k-%mMDb8gFJ{HeWhMK z`3jz#*@a{$nZHiIuV3e?)oKv1BfAdYA^%`=FdvFOxamL;M9`E3bV!6J*p3J$>CBt4 z4;J`>-jS~V3%AI4it%6`6n$`W3PA!|kiZjEcsmj>!4Tz|H&K#}qD-VxPbu6(!_2@3 z;HC{>OFlus7o{KsVBUDsNHQVcda<3SUFxb@LaU+jjZB}uiLLR g47>KNT&|?C`{m_`5-Y0JNbTwug_uiRYr)U{0gX9#>i_@% 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 c30c4aba976b7e498053eb11dae59d60922f17c9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 156 zcmZ?b<>g`kg0ESXF(CReh=2h`Aj1KOi&=m~3PUi1CZpd`(0P?VpQnp{#GRbv 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