protected override ConnectAck Read(byte[] bytes)
        {
            ValidateHeaderFlag(bytes, t => t == MqttPacketType.ConnectAck, 0x00);


            MqttProtocol.Encoding.DecodeRemainingLength(bytes, out int remainingLengthBytesLength);

            int connectAckFlagsIndex = MqttProtocol.PacketTypeLength + remainingLengthBytesLength;

            if (bytes.Byte(connectAckFlagsIndex).Bits(7) != 0x00)
            {
                throw new MqttException(ClientProperties.ConnectAckFormatter_InvalidAckFlags);
            }

            bool sessionPresent             = bytes.Byte(connectAckFlagsIndex).IsSet(0);
            MqttConnectionStatus returnCode = (MqttConnectionStatus)bytes.Byte(connectAckFlagsIndex + 1);

            if (returnCode != MqttConnectionStatus.Accepted && sessionPresent)
            {
                throw new MqttException(ClientProperties.ConnectAckFormatter_InvalidSessionPresentForErrorReturnCode);
            }

            ConnectAck connectAck = new ConnectAck(returnCode, sessionPresent);

            return(connectAck);
        }
예제 #2
0
 public ConnectAck(MqttConnectionStatus status, bool existingSession)
 {
     Status         = status;
     SessionPresent = existingSession;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MqttConnectionException" /> class,
 /// specifying the status and reason of the connection failure ,
 /// a specific error message and a reference to the inner exception that is the cause
 /// of this exception
 /// </summary>
 /// <param name="status">
 /// Code that represents the status and reason of the failure
 /// See <see cref="MqttConnectionStatus" /> for more information about the possible connection status values
 /// </param>
 /// <param name="message">The error message that explains the reason for the exception</param>
 /// <param name="innerException">The exception that is the cause of the current exception</param>
 public MqttConnectionException(MqttConnectionStatus status, string message, Exception innerException) : base(message, innerException)
 {
     ReturnCode = status;
 }
 public static string Client_ConnectNotAccepted(string clientId, MqttConnectionStatus status) => $"The connect packet of client {clientId} has not been accepted by the server. Status: {status}. The connection will be closed";
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MqttConnectionException" /> class,
 /// specifying the status and reason of the connection failure
 /// </summary>
 /// <param name="status">
 /// Code that represents the status and reason of the failure
 /// See <see cref="MqttConnectionStatus" /> for more information about the possible connection status values
 /// </param>
 public MqttConnectionException(MqttConnectionStatus status)
 {
     ReturnCode = status;
 }