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.
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://iot.eclipse.org:1883") opts.SetClientId("go-simple") opts.SetTraceLevel(MQTT.Off) opts.SetDefaultPublishHandler(f) opts.SetKeepAlive(30) //create and start a client using the above ClientOptions c := MQTT.NewClient(opts) _, err := c.Start() if err != nil { panic(err) } ...
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报