Pithikos / python-websocket-server

A simple fully working websocket-server in Python with no external dependencies
MIT License
1.14k stars 381 forks source link

[feature] Close a connection from the server side #58

Open Kio-td opened 6 years ago

Kio-td commented 6 years ago

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.

guilledk commented 6 years ago

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

efibutov commented 6 years ago

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

Pithikos commented 2 years ago

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.