python-websocket-server
python-websocket-server copied to clipboard
[feature] Close a connection from the server side
I think it'd be a really good idea incase a server needs to reject a connection from certain services, or disconnects at Client Request.
You can already do that by calling the function send_text
from the class WebSocketHandler, the function takes 2 parameters: "message" and the optional "opcode", to close the conection with a client call:
client['handler'].send_text("", opcode=0x8)
0x8 is OPCODE_CLOSE_CONN
send_text() got an unexpected keyword argument 'opcode'
It could be very useful to have a method that lets initiate disconnect from all the clients using Server's method (the shutdown method does not do the work, actually leaving the Server hanging forever...)
Shutting down of server has been implemented since v0.5.4. For shutting down individual clients that might need a new PR to add a new function (e.g. disconnect_client
) but the logic is already in the code.