diff options
Diffstat (limited to '')
| -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() | 
