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

query the state of a connection #799

Closed
kristjanvalur opened this issue Oct 14, 2021 · 3 comments
Closed

query the state of a connection #799

kristjanvalur opened this issue Oct 14, 2021 · 3 comments
Assignees

Comments

@kristjanvalur
Copy link

kristjanvalur commented Oct 14, 2021

Is your feature request related to a problem? Please describe.
Client logic that works with connects and reconnects may knot always know what the state of the connection is.
It is convenient to be able to check if a namespace is connected or disconnected. The javascript version of the library has a connected property on the connection.

Describe the solution you'd like
a function querying the status of a connection would be useful. Namespaces shoudld be supported.
so:

def get_state(self.namespace=""):
   # return "connected", "disconnected", "reconnecting" based on internal logic.

Such a method should also exist on the namespace class.

@miguelgrinberg
Copy link
Owner

The sio.connected attribute can be used to determine if the client is connected or disconnected/reconnecting. There is currently no distinction between a disconnected client and a client that is attempting to reconnect after the connection dropped. The sio.namespaces set contains the connected namespaces.

@kristjanvalur
Copy link
Author

Thanks. I guess I can determine the local reconnect state from whether the sio.wait() has returned or not.

Incidentally, I have an outer loop for the initial connect, performing the same kind of retry/backoff logic as the documented behaviour of the internal reconnect. I find that the internal reconnect sometimes failes (and sio.wait() exits) if a server responds with a 404 during a re-connection attempt, which can happen for example during a server update cycle.

@miguelgrinberg
Copy link
Owner

There are a couple of issues related to the reconnect not working in certain conditions: #485 and miguelgrinberg/python-engineio#254. Currently working on these.

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

No branches or pull requests

2 participants