|
|
|
|
@ -15,8 +15,6 @@ async def time_response(ws: WebSocketResponse, delay: int = 60):
|
|
|
|
|
await asyncio.sleep(delay)
|
|
|
|
|
except ConnectionResetError:
|
|
|
|
|
await asyncio.sleep(delay)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@template('index.html')
|
|
|
|
|
async def index(request):
|
|
|
|
|
return {}
|
|
|
|
|
@ -26,31 +24,28 @@ async def index_2(request):
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def websocket_handler(request):
|
|
|
|
|
ws: WebSocketResponse = WebSocketResponse()
|
|
|
|
|
await ws.prepare(request)
|
|
|
|
|
asyncio.create_task(time_response(ws))
|
|
|
|
|
async for msg in ws:
|
|
|
|
|
|
|
|
|
|
if msg.type == aiohttp.WSMsgType.TEXT:
|
|
|
|
|
|
|
|
|
|
if msg.data == 'close':
|
|
|
|
|
await ws.close()
|
|
|
|
|
else:
|
|
|
|
|
await ws.send_str(f'Вы послали: {msg.data}')
|
|
|
|
|
elif msg.type == WSMsgType.ERROR:
|
|
|
|
|
print('ws connection closed with exception %s' %
|
|
|
|
|
ws.exception())
|
|
|
|
|
ws: WebSocketResponse = WebSocketResponse()
|
|
|
|
|
await ws.prepare(request)
|
|
|
|
|
asyncio.create_task(time_response(ws))
|
|
|
|
|
async for msg in ws:
|
|
|
|
|
|
|
|
|
|
print('websocket connection closed')
|
|
|
|
|
if msg.type == aiohttp.WSMsgType.TEXT:
|
|
|
|
|
|
|
|
|
|
return ws
|
|
|
|
|
if msg.data == 'close':
|
|
|
|
|
await ws.close()
|
|
|
|
|
else:
|
|
|
|
|
await ws.send_str(f'Вы послали: {msg.data}')
|
|
|
|
|
elif msg.type == WSMsgType.ERROR:
|
|
|
|
|
print('ws connection closed with exception %s' %
|
|
|
|
|
ws.exception())
|
|
|
|
|
|
|
|
|
|
print('websocket connection closed')
|
|
|
|
|
|
|
|
|
|
return ws
|
|
|
|
|
async def button_clicked(request):
|
|
|
|
|
data = await request.post()
|
|
|
|
|
text = data.get('text')
|
|
|
|
|
response_text = f'Вы ввели: {text}'
|
|
|
|
|
print(response_text)
|
|
|
|
|
return Response(text=response_text)
|
|
|
|
|
data = await request.post()
|
|
|
|
|
text = data.get('text')
|
|
|
|
|
response_text = f'Вы ввели: {text}'
|
|
|
|
|
print(response_text)
|
|
|
|
|
return Response(text=response_text)
|