MqttConnectionKeepAlive constructor
MqttConnectionKeepAlive(
- MqttIConnectionHandler connectionHandler,
- int keepAliveSeconds
Initializes a new instance of the MqttConnectionKeepAlive class.
Implementation
MqttConnectionKeepAlive(
MqttIConnectionHandler connectionHandler, int keepAliveSeconds) {
_connectionHandler = connectionHandler;
keepAlivePeriod = keepAliveSeconds * 1000;
// Register for message handling of ping request and response messages.
connectionHandler.registerForMessage(
MqttMessageType.pingRequest, pingRequestReceived);
connectionHandler.registerForMessage(
MqttMessageType.pingResponse, pingResponseReceived);
connectionHandler.registerForAllSentMessages(messageSent);
// Start the timer so we do a ping whenever required.
pingTimer = Timer(Duration(milliseconds: keepAlivePeriod), pingRequired);
}