Ejemplo n.º 1
0
        public RecvForm()
        {
            InitializeComponent();

            _syncContext = SynchronizationContext.Current;

            _mqttClientHelper  = new MqttClientUtil.MqttClientHelper();
            _recvMessageHelper = new MessageHelper();
            _mqttMsgHandler    = new RecvMqttMsgHandler();

            _mqttClientHelper.OnMqttConnect     += OnMqttConnect;      //MQTT连接
            _mqttClientHelper.OnMqttMessage     += OnMqttMessage;      //MQTT接收消息
            _mqttClientHelper.OnErrorMessage    += OnMqttErrorMessage; //MQTT错误消息
            _recvMessageHelper.OnMessage        += OnRecvMessage;      //接收队列消息
            _mqttMsgHandler.OnLogMsg            += OnLogMsg;
            _mqttMsgHandler.OnErrorMsg          += OnErrorMsg;
            _mqttMsgHandler.OnPublishMsg        += OnPublishMsg;
            _mqttMsgHandler.OnRecvValueMsg      += OnRecvValueMsg;
            _mqttMsgHandler.OnRecvValueBeginMsg += OnRecvValueBeginMsg;
            _mqttMsgHandler.OnRecvValueEndMsg   += OnRecvValueEndMsg;

            _mqttClientHelper.InitMqttParas(
                MqttClientConstants.MqttClientRecvTopic,
                MqttClientConstants.MqttClientSendTopic,
                MqttClientConstants.MqttClientHeartbeatTopic,
                MqttMessageHandler.GetWillMessage());
            _recvMessageHelper.Start();
            _mqttMsgHandler.Init();
        }
Ejemplo n.º 2
0
        public SendForm()
        {
            InitializeComponent();

            _pingDic     = new Dictionary <string, PingInfo>();
            _syncContext = SynchronizationContext.Current;

            _mqttClientHelper  = new MqttClientUtil.MqttClientHelper();
            _sendMessageHelper = new SendMessageHelper();
            _recvMessageHelper = new MessageHelper();
            _mqttMsgHandler    = new SendMqttMsgHandler();

            _mqttClientHelper.OnMqttConnect  += OnMqttConnect;
            _mqttClientHelper.OnMqttMessage  += OnMqttRecvMessage;
            _mqttClientHelper.OnErrorMessage += OnMqttErrorMessage; //MQTT错误消息
            _sendMessageHelper.OnSendMessage += OnMqttSendMessage;
            _recvMessageHelper.OnMessage     += OnRecvMessage;
            _mqttMsgHandler.OnLogMsg         += OnLogMsg;
            _mqttMsgHandler.OnErrorMsg       += OnErrorMsg;
            _mqttMsgHandler.OnPublishMsg     += OnPublishMsg;
            _mqttMsgHandler.OnPangMsg        += OnPangMsg;

            _mqttClientHelper.InitMqttParas(
                MqttClientConstants.MqttClientSendTopic,
                MqttClientConstants.MqttClientRecvTopic,
                MqttClientConstants.MqttClientHeartbeatTopic,
                MqttMessageHandler.GetWillMessage());
            _recvMessageHelper.Start();
            _mqttMsgHandler.Init();
        }