2014-09-19 20:42
浏览 481

如何在Golang中更改客户端与代理之间的MQTT keepAlive(handshake)时间间隔?

I'm new in both GO and MQTT. After I started the client c := MQTT.NewClient(opts) c.Start() and until it disconnected each 30 sec. handshake traffic between client and broker showed up. I just need to adjust this interval or cancel handshake at all.

图片转代码服务由CSDN问答提供 功能建议

我在GO和MQTT中都是新手。 启动客户端后,c:= MQTT.NewClient(opts)c.Start(),直到每30秒断开一次。 客户与经纪人之间的握手流量出现了。 我只需要调整此间隔或完全取消握手即可。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhong5573 2014-09-19 21:02

    The keepAlive 'handshake' is required it can not be disabled, it is how the broker knows the client is still connected.

    You can change the keepalive timeout by calling SetKeepAlive on the opts object before passing it to the NewClient method.

    This method takes a value in seconds for the time between each keepAlive packet.

    Using the sample code here, you would add a line like this to set the KeepAlive timeout to 30 seconds.

      opts := MQTT.NewClientOptions().SetBroker("tcp://")
      //create and start a client using the above ClientOptions
      c := MQTT.NewClient(opts)
      _, err := c.Start()
      if err != nil {
    点赞 评论

相关推荐 更多相似问题