From cf999735856504fee0bfe74d9b66e764b71ae746 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Tue, 13 Feb 2018 10:45:57 +0000 Subject: Websocket echo test --- ws_app.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ws_app.py (limited to 'ws_app.py') diff --git a/ws_app.py b/ws_app.py new file mode 100644 index 00000000..a9f60175 --- /dev/null +++ b/ws_app.py @@ -0,0 +1,27 @@ +# coding=utf-8 + +from collections import OrderedDict + +from geventwebsocket import Resource, WebSocketApplication, WebSocketServer + + +class EchoApplication(WebSocketApplication): + def on_open(self): + print("Connection opened") + + def on_message(self, message, **kwargs): + print(f"<- {message}") + self.ws.send(message) + print(f"-> {message}") + + def on_close(self, reason): + print(reason) + + +if __name__ == "__main__": + app = WebSocketServer( + ('', 8000), + Resource(OrderedDict([('/ws/echo', EchoApplication)])) + ) + + app.serve_forever() -- cgit v1.2.3