Compare commits

..

2 Commits

Author SHA1 Message Date
kirill 5537418968 Fixed a bug in the function time_response 2 years ago
kirill 8e981e28f9 reformat 2 years ago
  1. 3
      demo/func/secondary_functions.py
  2. 9
      demo/views/frontend.py
  3. 2
      entry.py

@ -17,4 +17,5 @@ async def time_response(ws: WebSocketResponse, delay: int = 60):
await ws.send_str(result_response)
await asyncio.sleep(delay)
except ConnectionResetError:
await asyncio.sleep(delay)
break

@ -21,19 +21,12 @@ async def websocket_handler(request):
await ws.prepare(request)
asyncio.create_task(secondary_functions.time_response(ws, delay=60))
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}')
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

@ -6,4 +6,4 @@ app = create_app()
if __name__ == '__main__':
aiohttp.web.run_app(app)
# Добавить 2 страничку, подключить ws, отправлял текущие время раз в минуту. Ну и также отвечать на собщения.

Loading…
Cancel
Save