python-websocket-server icon indicating copy to clipboard operation
python-websocket-server copied to clipboard

[feature] Close a connection from the server side

Open Kio-td opened this issue 6 years ago • 3 comments

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.

Kio-td avatar Jul 16 '18 17:07 Kio-td

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

guilledk avatar Jul 17 '18 00:07 guilledk

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...)

efibutov avatar Aug 09 '18 03:08 efibutov

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.

Pithikos avatar Nov 15 '21 11:11 Pithikos