Git Product home page Git Product logo

Comments (8)

shamblett avatar shamblett commented on August 11, 2024

If you are using the autoreconnect functionality it will run till it reconnects unless you stop it.

I cant comment on why this affects your ui.

from mqtt5_client.

lucasjinreal avatar lucasjinreal commented on August 11, 2024

shall make connect function be a async function?

Currently it happens when network are not stable, don't why

from mqtt5_client.

shamblett avatar shamblett commented on August 11, 2024

If your network is so unstable you can't connect then you ate going to have trouble with MQTT. It makes no difference to the client whether its sync or async, if you can't connect you are stuck. You need to put the client as a whole on its own isolate maybe.

from mqtt5_client.

lucasjinreal avatar lucasjinreal commented on August 11, 2024

Is there any reconnect timeout try times or interval time params to set?
Currently it will reonnect quickly when network unstable (note: not offline, if offline I can detect, but network not stable or slow I can not really detect this)

from mqtt5_client.

shamblett avatar shamblett commented on August 11, 2024

You can change the amount of retries, see the API spec. You could monitor the connect callback, if this is not called after a time interval you could disconnect, back off and try connecting later.

from mqtt5_client.

lucasjinreal avatar lucasjinreal commented on August 11, 2024

@shamblett thanks.

I have set maxReconnectTimes to 3:

 _client =
          MqttServerClient.withPort(host, cid, 1883, maxConnectionAttempts: 3);
      // MqttServerClient.withPort("test.mosquitto.org", cid, 1883,
      // maxConnectionAttempts: 3);
      kLog(
          '!!!! ------------> [conn] connect with $host, $port, $username, $password, ${_clientId} $_client');

      // _client!.logging(on: true);
      _client!.logging(on: false);
      _client!.onConnected = onConnected;
      _client!.onDisconnected = onDisconnected;
      _client!.onUnsubscribed = onUnsubscribed;
      _client!.onSubscribed = onSubscribed;
      _client!.onSubscribeFail = onSubscribeFail;
      _client!.onAutoReconnect = onAutoReconnect;
      _client!.pongCallback = pong;
      _client!.keepAlivePeriod = 60 * 3;
      _client!.autoReconnect = true;
      _client!.useWebSocket = useWebsocket;

      final connMessage = MqttConnectMessage()
          .authenticateAs(username, password)
          .withSessionExpiryInterval(3600 * 24 * 14) // last for 7 days
          .keepAliveFor(120)
          // .withWillTopic('lastwills')
          // .withWillMessage('Will message')
          .withClientIdentifier(cid);
      // .withProtocolName("MQTT")
      // .withProtocolVersion(4)
      // .withSessionExpiryInterval(interval)
      // .withWillQos(MqttQos.atLeastOnce);
      _client!.connectionMessage = connMessage;

But, when the network are poor, the connect actually connects, but it still will reconnect, ( i have receive the connected welcome message).

Can u give me some suggestions, why I set max tries and reconnect, it will reconnect repeatly very quickly?

from mqtt5_client.

shamblett avatar shamblett commented on August 11, 2024

Your using autoreconnect = true so post initial connection.if the connection is lost the client will try and reconnect automatically forever.

If you turn this off you can control when you reconnect after a disconnect using the onConnected/onDisconnected callbaclks.

from mqtt5_client.

lucasjinreal avatar lucasjinreal commented on August 11, 2024

Your using autoreconnect = true so post initial connection.if the connection is lost the client will try and reconnect automatically forever.

If you turn this off you can control when you reconnect after a disconnect using the onConnected/onDisconnected callbaclks.

thanks, how to turn it off? You mean do not auto reconnect? But I need auto reconnect, in case people offline it will auto reconnect,

but the problem is the reconnect interval are too quicky

from mqtt5_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.