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

How to close connection to a client? #53

Open
davidwaltre opened this issue Feb 12, 2021 · 4 comments
Open

How to close connection to a client? #53

davidwaltre opened this issue Feb 12, 2021 · 4 comments

Comments

@davidwaltre
Copy link

davidwaltre commented Feb 12, 2021

Hello,

I am using the library for a connection between two ESP8266 (one client, one broker). It works so far. (I'm also using the client from this library.)
But as soon as the client restarts, and tries to connect with the same ClientID, it disconnects again. After waiting four minutes, the broker disconnects the inactive client connection and the new client connects as it should.
(Same thing when the broker goes down, the client reconnects after some time has passed. Is that linked?)

I worked around this by using a randomly generated ClientID.

Now if the client restarts a couple of times, the broker has too many connections, to clients that are not in use anymore.

My idea: As I only every have one client in use with that broker, I wanted to close the previous client connection on every new connection.

My questions:

  1. Why does the broker close the old connection and the client reconnect only after four minutes, and how can I change that time interval? Is that the time the client checks is the connection is still working, or is that broker-sided?

  2. How can I close a connection to a specific client? Or close all current connections?

Thanks in advance!

@martin-ger
Copy link
Owner

Think, the problem could be, that the client doesn't terminate the MQTTT/TCP-session correctly. Thus the session stays alive untill the timeout happens. You say, the client "restarts". What happens here - does it close its TCP connection before restarting or is it just a reset?

@davidwaltre
Copy link
Author

davidwaltre commented Feb 13, 2021

The client restarts through the reset button, or because it gets disconnected to power and reconnected later on. As I'm developing a relais on one of the ESP8266 that gets its commands from a button on the other ESP8266 and through a small one-button-website hosted on itself (I'll work on that website part later on), I think that the broker usually does not reset / restart.

My only concern now is that when the Client loses connection or resets, the broker will sooner or later have too many open connections so the Client can't connect anymore (using a random ClientID).

I'm thinking about restarting the broker when the Client connects a fourth/fifth time (with publishing a message before restarting - so the client knows it has to reconnect). In everyday use of the two components, I don't think the client will reset very often - but I also don't know for sure. And if it does reset, it most certainly can not close its connections due to the unforeseen resets.

Edit: As I thought about it, the dead connections are also dropped after four minutes. As the client probably doesn't reconnect that often in four minutes, I'll rely on that if I won't find any better solution.

@Sinix10
Copy link

Sinix10 commented Oct 4, 2021

Think, the problem could be, that the client doesn't terminate the MQTTT/TCP-session correctly. Thus the session stays alive untill the timeout happens. You say, the client "restarts". What happens here - does it close its TCP connection before restarting or is it just a reset?

Please, tell us how to change the "timeout" time, pls? I really need to change it.

Thanks

@martin-ger
Copy link
Owner

You will find the timeout values in "defaults.h".

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