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

[QUESTION] What is keepAlivePeriod? #554

Open
rpungin opened this issue Jul 26, 2024 · 2 comments
Open

[QUESTION] What is keepAlivePeriod? #554

rpungin opened this issue Jul 26, 2024 · 2 comments

Comments

@rpungin
Copy link

rpungin commented Jul 26, 2024

Dear @shamblett, from your docs I see:

  /// Keep alive period, seconds.
  /// Keep alive is defaulted to off, this must be set to a valid value to
  /// enable keep alive.
  int keepAlivePeriod = MqttClientConstants.defaultKeepAlive;

But what exactly is "keep alive" in this context and what should the value of this parameter be for a Flutter app? I have seen examples where this value was set to 30 and some examples where it is set to 1200.

Is this parameter value also dependent on some other parameters, like autoReconnect? I think you mentioned that autoReconnect should be set to false for Flutter mobile apps and reconnection should be managed manually. Is that correct?

@shamblett
Copy link
Owner

These settings are nothing to with flutter or your application being a mobile application, they are part of the MQTT specification, see sections 3.12 and 3.13 or just type 'keepalive' in the search bar of the package API.

Autoreconnect can be set to anything you want for your use case, the platform makes no difference.

What I said was autoreconnect was not intended to recover from known platform events like foreground/background its more intended for sudden network/broker failure, some users use this, some users prefer to use keepalive to monitor broker/network availability, again your preference.

What issue are you reporting here? If your saying the package API documentation is unclear/wrong in these areas then please document this and I'll have a look at it.

@rpungin
Copy link
Author

rpungin commented Aug 1, 2024

Thank you for the link to the specification, @shamblett !

Here is the extract from it in case someone else is looking for this information.

The Keep Alive is a time interval measured in seconds. Expressed as a 16-bit word, it is the maximum time interval that is permitted to elapse between the point at which the Client finishes transmitting one Control Packet and the point it starts sending the next. It is the responsibility of the Client to ensure that the interval between Control Packets being sent does not exceed the Keep Alive value. In the absence of sending any other Control Packets, the Client MUST send a PINGREQ Packet [MQTT-3.1.2-23].

The Client can send PINGREQ at any time, irrespective of the Keep Alive value, and use the PINGRESP to determine that the network and the Server are working.

If the Keep Alive value is non-zero and the Server does not receive a Control Packet from the Client within one and a half times the Keep Alive time period, it MUST disconnect the Network Connection to the Client as if the network had failed [MQTT-3.1.2-24].

If a Client does not receive a PINGRESP Packet within a reasonable amount of time after it has sent a PINGREQ, it SHOULD close the Network Connection to the Server.

A Keep Alive value of zero (0) has the effect of turning off the keep alive mechanism. This means that, in this case, the Server is not required to disconnect the Client on the grounds of inactivity.
Note that a Server is permitted to disconnect a Client that it determines to be inactive or non-responsive at any time, regardless of the Keep Alive value provided by that Client.

So my next question is:

What is the recommended value for keepAlive parameter for a Flutter app working with AWS IoT MQTT Broker? Should I disable it by setting it to zero or should I set it to some specific number and if so what that number should be based off?

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

2 participants