Exemple #1
0
        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());
                }
            }
        }
Exemple #2
0
 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);
     }
 }
Exemple #3
0
 public void Disconnect()
 {
     manager.SendMessage(new MqttDisconnectMessage());
     if (keepAliveTimer != null)
     {
         keepAliveTimer.Dispose();
         keepAliveTimer = null;
     }
     manager.Disconnect();
 }