예제 #1
0
        public async Task HandleClientDisconnectedAsync(MqttServerClientDisconnectedEventArgs eventArgs)
        {
            var message = new MqttDisconnectMessage()
            {
                ClientId = eventArgs.ClientId,
            };

            if (string.Equals(message.ClientId, _configuration.GetSection("MQTT").GetSection("MqttClientEnactorName").Value) == false)
            {
                await _endpoint.Request <HttpStatusCode>(message).ConfigureAwait(false);
            }
        }
예제 #2
0
        public void BasicSerialization()
        {
            // Message Specs________________
            // <E0><00>
            var expected = new[]
            {
                (byte)0xE0,
                (byte)0x00
            };

            MqttDisconnectMessage msg = new MqttDisconnectMessage();

            Console.WriteLine(msg);

            byte[] actual = MessageSerializationHelper.GetMessageBytes(msg);

            Assert.Equal <int>(expected.Length, actual.Length);
            Assert.Equal <byte>(expected[0], actual[0]); // first header byte
            Assert.Equal <byte>(expected[1], actual[1]); // message size byte
        }
예제 #3
0
        /// <summary>
        /// Parse bytes for a DISCONNECT message
        /// </summary>
        /// <param name="fixedHeaderFirstByte">First fixed header byte</param>
        /// <param name="protocolVersion">Protocol Version</param>
        /// <param name="channel">Channel connected to the broker</param>
        /// <returns>DISCONNECT message instance</returns>
        public static MqttDisconnectMessage Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
        {
            MqttDisconnectMessage msg = new MqttDisconnectMessage();

            if (protocolVersion == MqttConnectMessage.PROTOCOL_VERSION_V3_1_1)
            {
                // [v3.1.1] check flag bits
                if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_DISCONNECT_FLAG_BITS)
                {
                    throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
                }
            }

            // get remaining length and allocate buffer
            int remainingLength = MqttMessage.DecodeRemainingLength(channel);

            // NOTE : remainingLength must be 0

            return(msg);
        }