Exemple #1
0
        private void DoReconnect()
        {
            switch (ConnectionState)
            {
            case MQTT.ConnectionState.Connected:
            case MQTT.ConnectionState.Connecting:
                return;
            }

            if (m_shouldReconnect)
            {
                // make sure we don't ask more than once
                if (m_reconnecting)
                {
                    return;
                }
                m_reconnecting = true;

                TracingDebug("MQTTBrokerProxy: Queueing up an auto-reconnect...");
                try
                {
                    TracingDebug("MQTTBrokerProxy: Reconnecting...");
                    Connect(BrokerHostName, BrokerPort);

                    if (ConnectionState == MQTT.ConnectionState.Connecting)
                    {
                        Send(new Connect(m_lastUserName, m_lastPassword, m_lastClientIdentifier));
                        if (autoResetConnEvent.WaitOne(5000, false))
                        {
                            #region 重新订阅主题
                            if (Subscriptions.m_subscriptions != null && Subscriptions.m_subscriptions.Count > 0)
                            {
                                List <Subscription> subscribeList = Subscriptions.m_subscriptions.Values.ToList();
                                Subscriptions_SubscriptionAdded(null, new GenericEventArgs <List <Subscription> >(subscribeList));
                            }
                            ReconnectedMqtt?.Invoke(null, null);
                            #endregion
                        }
                    }
                    m_reconnecting = false;
                }
                catch
                {
                    m_reconnecting = false;
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// 方法说明:MQTT断开重连事件
 /// 完成时间:2016-04-20
 /// </summary>
 /// <param name="sender">MQTT断开重连触发</param>
 /// <param name="e">MQTT断开重连事件信息</param>
 private void OnReconnectedMqtt(object sender, EventArgs e)
 {
     ReconnectedMqtt?.Invoke(null, null);
 }