Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (!CheckSendParas())
            {
                return;
            }

            if (_loop)
            {
                _sendMessageHelper.Stop();
                _sendMessageHelper.Start(1000 / _fps, _sendValue);
            }
            else
            {
                _mqttClientHelper.SendMessage(SendMessageHelper.GetSendMessage(_sendValue));
            }
        }