2017-02-20 20:25:44 +00:00
|
|
|
from sanic import Sanic
|
2021-09-29 11:09:23 +01:00
|
|
|
from sanic.response import redirect
|
2017-02-20 20:25:44 +00:00
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
|
2017-02-20 20:25:44 +00:00
|
|
|
app = Sanic(__name__)
|
|
|
|
|
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
app.static("index.html", "websocket.html")
|
|
|
|
|
2017-02-20 20:25:44 +00:00
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
@app.route("/")
|
2021-09-29 11:09:23 +01:00
|
|
|
def index(request):
|
|
|
|
return redirect("index.html")
|
2017-02-20 20:25:44 +00:00
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
|
|
|
|
@app.websocket("/feed")
|
2017-02-20 20:25:44 +00:00
|
|
|
async def feed(request, ws):
|
|
|
|
while True:
|
2021-11-23 21:00:25 +00:00
|
|
|
data = "hello!"
|
|
|
|
print("Sending: " + data)
|
2017-02-20 20:25:44 +00:00
|
|
|
await ws.send(data)
|
|
|
|
data = await ws.recv()
|
2021-11-23 21:00:25 +00:00
|
|
|
print("Received: " + data)
|
2017-02-20 20:25:44 +00:00
|
|
|
|
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
if __name__ == "__main__":
|
2017-06-01 19:53:05 +01:00
|
|
|
app.run(host="0.0.0.0", port=8000, debug=True)
|