-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
28 lines (26 loc) · 773 Bytes
/
test.py
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
28
from bottle import request, Bottle
from wsocket import WebSocketHandler,logger
from sl.server import ThreadingWSGIServer
from time import sleep
logger.setLevel(10)
app = Bottle()
@app.route('/')
def handle_websocket():
wsock = request.environ.get('wsgi.websocket')
if not wsock:
return 'Hello World!'
while True:
message = wsock.receive()
if not message:
break
print(message)
wsock.send('Your message was: %r' % message)
sleep(3)
wsock.send('Your message was: %r' % message)
httpd = ThreadingWSGIServer(('localhost',9001),WebSocketHandler)
httpd.set_app(app)
print('WSGIServer: Serving HTTP on port 9001 ...\n')
try:
httpd.serve_forever()
except:
print('WSGIServer: Server Stopped')