blob: a9f60175d8d42289d563fdbb76a5c88d93aec227 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()
|