Python Forum
web socket server handle onnection closed abnormally [internal])
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
web socket server handle onnection closed abnormally [internal])
#1
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:
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)
when I turn off the client with
ws.close()
I get this:

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)
2 questions:
1. why am I still seeing this line:
Got request ('10.0.0.111', 53739)
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:

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())
thanks,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  This result object does not return rows. It has been closed automatically dawid294 6 1,004 Mar-30-2024, 03:08 AM
Last Post: NolaCuriel
  A question about 'Event loop is closed' fc5igm 2 2,201 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  How to take the tar backup files form remote server to local server sivareddy 0 1,895 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  500 internal server error Nitil 1 2,875 May-01-2021, 06:16 PM
Last Post: snippsat
  ValueError: I/O operation on closed file problem aliwien 0 2,107 Apr-23-2021, 05:50 PM
Last Post: aliwien
  Run an app in a standalone terminal and wait until it's closed glestwid 2 2,510 Aug-30-2020, 08:14 AM
Last Post: glestwid
  Removing internal brackets from a string Astrikor 4 2,661 Jun-04-2020, 07:54 PM
Last Post: Astrikor
  Internal Server Error 500 on creating .py file patrickluethi 0 1,744 Aug-02-2019, 01:57 PM
Last Post: patrickluethi
  Capturing inputs values from internal python script limors11 11 5,183 Jun-16-2019, 05:05 PM
Last Post: DeaD_EyE
  Inclusive (closed) range with float numbers mapg 4 3,971 Apr-27-2019, 09:09 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020