Files
microdot/examples/websocket/echo_asgi.py
Miguel Grinberg 20ea305fe7 v2 (#186)
2023-12-22 20:26:07 +00:00

21 lines
347 B
Python

from microdot.asgi import Microdot, send_file, with_websocket
app = Microdot()
@app.route('/')
async def index(request):
return send_file('index.html')
@app.route('/echo')
@with_websocket
async def echo(request, ws):
while True:
data = await ws.receive()
await ws.send(data)
if __name__ == '__main__':
app.run()