1async def application(scope, receive, send): 2 if scope['type'] == 'websocket': 3 while True: 4 m = await receive() 5 if m['type'] == 'websocket.connect': 6 await send({'type': 'websocket.accept'}) 7 8 if m['type'] == 'websocket.receive': 9 await send( 10 { 11 'type': 'websocket.send', 12 'bytes': m.get('bytes', None), 13 'text': m.get('text', None), 14 } 15 ) 16 17 if m['type'] == 'websocket.disconnect': 18 break 19