|
@@ -0,0 +1,38 @@
|
|
|
+import asyncio
|
|
|
+import json
|
|
|
+import pysqlite3 as sql
|
|
|
+import sanic
|
|
|
+
|
|
|
+app = sanic.Sanic()
|
|
|
+
|
|
|
+@app.route("/static/<f>")
|
|
|
+async def static(request, f):
|
|
|
+ return await sanic.response.file('static/{}'.format(f))
|
|
|
+
|
|
|
+@app.route("/")
|
|
|
+async def index(request):
|
|
|
+ return await sanic.response.file('static/index.html')
|
|
|
+
|
|
|
+@app.websocket("/socket")
|
|
|
+async def socket(request, ws):
|
|
|
+ initial = await ws.recv()
|
|
|
+ config = json.loads(initial)
|
|
|
+ sanic.log.logger.info('connected websocket for {} in game {}'.format(
|
|
|
+ config['user'],
|
|
|
+ config['game']))
|
|
|
+
|
|
|
+ for x in range(50):
|
|
|
+ await ws.send(json.dumps({"author": "server", "content": str(x)}))
|
|
|
+ await asyncio.sleep(1)
|
|
|
+ # await ws.send(json.dumps({"author": "server", "content": "two"}))
|
|
|
+ # await asyncio.sleep(1)
|
|
|
+ # await ws.send(json.dumps({"author": "server", "content": "three"}))
|
|
|
+ # while True:
|
|
|
+ # data = 'hello!'
|
|
|
+ # print('Sending: ' + data)
|
|
|
+ # await ws.send(data)
|
|
|
+ # data = await ws.recv()
|
|
|
+ # print('Received: ' + data)
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ app.run()
|