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:
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)
when I turn off the client with
1
ws.close()
I get this:

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)
2 questions:
1. why am I still seeing this line:
1
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:

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  asyncio: WebSocketClient:connection closed (ERR): sent 1011 Michel777 0 514 Feb-04-2025, 09:22 PM
Last Post: Michel777
  How to umount on a closed distro ebolisa 5 1,290 Jan-03-2025, 03:50 AM
Last Post: DeaD_EyE
  A question about 'Event loop is closed' fc5igm 3 5,466 Oct-01-2024, 09:12 AM
Last Post: skdaro
  [closed] check whether an integer is 32 or 64 bits paul18fr 4 5,571 May-27-2024, 04:55 PM
Last Post: deanhystad
  How to take the tar backup files form remote server to local server sivareddy 0 2,617 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  500 internal server error Nitil 1 3,881 May-01-2021, 06:16 PM
Last Post: snippsat
  ValueError: I/O operation on closed file problem aliwien 0 2,739 Apr-23-2021, 05:50 PM
Last Post: aliwien
  Run an app in a standalone terminal and wait until it's closed glestwid 2 3,475 Aug-30-2020, 08:14 AM
Last Post: glestwid
  Removing internal brackets from a string Astrikor 4 3,888 Jun-04-2020, 07:54 PM
Last Post: Astrikor
  Internal Server Error 500 on creating .py file patrickluethi 0 2,438 Aug-02-2019, 01:57 PM
Last Post: patrickluethi

Forum Jump:

User Panel Messages

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