Sep-23-2021, 09:26 AM
Hello,
using web socket server to send data to user
now , when I shut down the client usinc CTRL+C I get this error on the server:
when I turn off the client with
I get this:
2 questions:
1. why am I still seeing this line:
nothing is connected to the server on both cases?
2. how do I handle the error ? and tell him to print it only one time?
this is the full code:
thanks,
using web socket server to send data to user
now , when I shut down the client usinc CTRL+C I get this error on the server:
1 2 3 4 5 6 7 8 9 10 11 12 |
code = 1006 (connection closed abnormally [internal]), no reason Got request ( '10.0.0.111' , 53739 ) code = 1006 (connection closed abnormally [internal]), no reason Got request ( '10.0.0.111' , 53739 ) code = 1006 (connection closed abnormally [internal]), no reason Got request ( '10.0.0.111' , 53739 ) code = 1006 (connection closed abnormally [internal]), no reason Got request ( '10.0.0.111' , 53739 ) code = 1006 (connection closed abnormally [internal]), no reason Got request ( '10.0.0.111' , 53739 ) code = 1006 (connection closed abnormally [internal]), no reason Got request ( '10.0.0.111' , 53739 ) |
1 |
ws.close() |
1 2 3 4 5 6 7 8 9 10 |
code = 1000 (OK), no reason Got request ( '10.0.0.111' , 59060 ) code = 1000 (OK), no reason Got request ( '10.0.0.111' , 59060 ) code = 1000 (OK), no reason Got request ( '10.0.0.111' , 59060 ) code = 1000 (OK), no reason Got request ( '10.0.0.111' , 59060 ) code = 1000 (OK), no reason Got request ( '10.0.0.111' , 59060 ) |
1. why am I still seeing this line:
1 |
Got request ( '10.0.0.111' , 53739 ) |
2. how do I handle the error ? and tell him to print it only one time?
this is the full code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import asyncio import time import websockets from datetime import datetime import random TS = "TS" RN = "RN" async def David(websocket, path): while True : try : remote_ip = websocket.remote_address print ( 'Got request ' + str (remote_ip)) await websocket.send(TS + "!" + str (RN)) await asyncio.sleep( 1 ) except asyncio.exceptions.IncompleteReadError as e2: print (e2) except websockets.exceptions.ConnectionClosedError as E1: print (E1) except Exception as e: print (e) async def time_update(): while True : global TS TS = datetime.now().strftime( '%d-%m-%y %H-%M-%S-%f' ) print (TS) await asyncio.sleep( 0.742 ) async def randomNumber(): while True : global RN RN = random.randrange( 0 , 10000 , 1 ) print (RN) await asyncio.sleep( 0.217 ) async def main(): asyncio.get_event_loop().create_task(time_update()) asyncio.get_event_loop().create_task(randomNumber()) async with websockets.serve(David, "10.0.0.111" , 8765 ): print ( "server started" ) await asyncio.Future() asyncio.run(main()) |