Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnection support from server #1

Closed
tito opened this issue Jul 15, 2015 · 9 comments
Closed

Disconnection support from server #1

tito opened this issue Jul 15, 2015 · 9 comments

Comments

@tito
Copy link

tito commented Jul 15, 2015

There is no current way to stop a connection of a client from the server.

Flask socketio have a disconnect function that can be used to stop the connection of the current client. This can be used in few cases like when the authentication failed, etc.

Ref: https://flask-socketio.readthedocs.org/en/latest/#flask.ext.socketio.disconnect

@miguelgrinberg
Copy link
Owner

In the connect event handler you can return False to reject a connection. As far as disconnecting from the server, I'll have to see how if the Socket.IO protocol allows that, I don't think I've seen a way to do that.

@tito
Copy link
Author

tito commented Jul 15, 2015

Disconnect (in my case) is require also in others function that the connect (i don't have all the users information during the initial connection, only after the auth process.).

So returning False is not enough :)

@miguelgrinberg
Copy link
Owner

Yes, I agree that disconnect can be useful. I just couldn't find how to implement it, need to read the js client code more carefully to see what can I send it to close a connection, or maybe just fake it, which is to keep it open but don't let any messages in or out.

@miguelgrinberg
Copy link
Owner

This is now available. Closing.

@QuingZ
Copy link

QuingZ commented Dec 20, 2016

Just wondering how it is implemented eventually, closing the socket connection or faking disconnect?
I am using python-socketio-1.6.0 to setup a server, and facing a problem that the tcp socket are stilled in ESTAB status after invoking socketio.Server.disconnect(). Not sure it is related to this issue or not?

Thanks.

@miguelgrinberg
Copy link
Owner

@QuingZ This discussion was regarding disconnecting from the client. Disconnecting from the server has been implemented long ago and as far as I know works fine. If you try the example in this app, there is a disconnect button that triggers a server-initiated disconnection.

@QuingZ
Copy link

QuingZ commented Dec 21, 2016

I am using python-socketio-client to connect to server. After socketio.disconnect() is invoked from server, the client can receive "disconnect" message. However, when checking the socket connection by "ss -at", I found that the socket is not closed unless the client process is closed or terminated. My question is that, does disconnecting from the server close the tcp socket, or just keep the socket open but doesn't let any messages in or out? Thanks.

@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Dec 21, 2016

That really depends on the WebSocket implementation. This package is not managing the connection at the socket level, it relies on a base WebSocket implementation to do that, and there are currently three of these that are supported. I guess it is possible that when the connection ends there is no proper cleanup of the underlying socket, but that would be something to investigate on the particular WebSocket implementation you are using (eventlet, gevent or uwsgi).

@QuingZ
Copy link

QuingZ commented Dec 21, 2016

I see. I am using eventlet, seems it doesn't close socket properly. I will do same research on it, hopefully can find something.
Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants