diff options
-rwxr-xr-x | main.py | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -38,7 +38,7 @@ async def handle_client(reader, writer): except Exception: break - data = None + data = 'unknown' if request == 'on': await relay_set(ON) logger.info('set on') @@ -54,9 +54,15 @@ async def handle_client(reader, writer): data = 'on' if status is True else 'off' writer.write((data + '\r\n').encode('utf-8')) - await writer.drain() + try: + await writer.drain() + except ConnectionError: + break - writer.close() + try: + writer.close() + except ConnectionError: + pass async def run_server(host, port): |