protected void OnConnectionLost(EventArgs e) { if (keepAliveTimer != null) { keepAliveTimer.Dispose(); keepAliveTimer = null; } if (ConnectionLost != null) { try { ConnectionLost(this, e); } catch (Exception ex) { MqttClient.Logger.Log.Write(LogLevel.ERROR, "MqttLib: Uncaught exception from user delegate: " + ex.ToString()); } } }
private void DoConnect(MqttConnectMessage conmsg) { try { manager.Connect(); manager.SendMessage(conmsg); manager.WaitForResponse(); TimerCallback callback = new TimerCallback(tmrCallback); // TODO: Set Keep Alive interval and keepAlive time as property of client int keepAliveInterval = 1000 * _keepAlive; keepAliveTimer = new Timer(callback, null, keepAliveInterval, keepAliveInterval); } catch (Exception e) { throw new MqttBrokerUnavailableException("Unable to connect to the broker", e); } }
public void Disconnect() { manager.SendMessage(new MqttDisconnectMessage()); if (keepAliveTimer != null) { keepAliveTimer.Dispose(); keepAliveTimer = null; } manager.Disconnect(); }