diff options
author | 2018-02-13 10:45:57 +0000 | |
---|---|---|
committer | 2018-02-13 10:45:57 +0000 | |
commit | cf999735856504fee0bfe74d9b66e764b71ae746 (patch) | |
tree | dd08cb6cc372b750732099e42e7f9b9b557d2b28 /ws_app.py | |
parent | fix typo (diff) |
Websocket echo test
Diffstat (limited to 'ws_app.py')
-rw-r--r-- | ws_app.py | 27 |
1 files changed, 27 insertions, 0 deletions
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() |