Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

websockets.exceptions.ConnectionClosedError: code = 1011 (unexpected error), no reason

The server close connection for the client after a while and client disconnect automatically after try to send a message :

    newmsg = await websocket.recv()
like image 469
Adil Saidi Avatar asked Jul 16 '26 01:07

Adil Saidi


1 Answers

the problem is the server is sending pings to the client and try to get a response which is the newmsg, when the msg is not sent back then the server close the connection after 20 sec which is the default value, the solution is to desactivate the ping from the server and the client if you want : server.py:

start_server = websockets.serve(receive_name, "localhost", 8765,ping_interval=None)

client.py :

    async with websockets.connect(uri, ping_interval=None) as websocket:
like image 105
Adil Saidi Avatar answered Jul 18 '26 15:07

Adil Saidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!