[NF] Mqtt library changed
This commit is contained in:
parent
68b7fb28c6
commit
3c2ef745a5
@ -20,6 +20,6 @@ Global
|
|||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {E4CE8710-7B51-439F-A427-9AEFFE71E682}
|
SolutionGuid = {135814CF-A469-4436-9C51-3CFE4B93D2FE}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -23,7 +21,7 @@ namespace uPLibrary.Networking.M2Mqtt.Exceptions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// MQTT client exception
|
/// MQTT client exception
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttClientException : ApplicationException
|
public class MqttClientException : Exception
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
@ -53,9 +51,9 @@ namespace uPLibrary.Networking.M2Mqtt.Exceptions
|
|||||||
public enum MqttClientErrorCode
|
public enum MqttClientErrorCode
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will topic length error
|
/// Will error (topic, message or QoS level)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
WillTopicWrong = 1,
|
WillWrong = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Keep alive period too large
|
/// Keep alive period too large
|
||||||
@ -100,6 +98,35 @@ namespace uPLibrary.Networking.M2Mqtt.Exceptions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrong Message Id
|
/// Wrong Message Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
WrongMessageId
|
WrongMessageId,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Inflight queue is full
|
||||||
|
/// </summary>
|
||||||
|
InflightQueueFull,
|
||||||
|
|
||||||
|
// [v3.1.1]
|
||||||
|
/// <summary>
|
||||||
|
/// Invalid flag bits received
|
||||||
|
/// </summary>
|
||||||
|
InvalidFlagBits,
|
||||||
|
|
||||||
|
// [v3.1.1]
|
||||||
|
/// <summary>
|
||||||
|
/// Invalid connect flags received
|
||||||
|
/// </summary>
|
||||||
|
InvalidConnectFlags,
|
||||||
|
|
||||||
|
// [v3.1.1]
|
||||||
|
/// <summary>
|
||||||
|
/// Invalid client id
|
||||||
|
/// </summary>
|
||||||
|
InvalidClientId,
|
||||||
|
|
||||||
|
// [v3.1.1]
|
||||||
|
/// <summary>
|
||||||
|
/// Invalid protocol name
|
||||||
|
/// </summary>
|
||||||
|
InvalidProtocolName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -23,7 +21,7 @@ namespace uPLibrary.Networking.M2Mqtt.Exceptions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exception due to error communication with broker on socket
|
/// Exception due to error communication with broker on socket
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttCommunicationException : ApplicationException
|
public class MqttCommunicationException : Exception
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor
|
/// Default constructor
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -23,7 +21,7 @@ namespace uPLibrary.Networking.M2Mqtt.Exceptions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connection to the broker exception
|
/// Connection to the broker exception
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttConnectionException : ApplicationException
|
public class MqttConnectionException : Exception
|
||||||
{
|
{
|
||||||
public MqttConnectionException(string message, Exception innerException)
|
public MqttConnectionException(string message, Exception innerException)
|
||||||
: base(message, innerException)
|
: base(message, innerException)
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -23,7 +21,7 @@ namespace uPLibrary.Networking.M2Mqtt.Exceptions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timeout on receiving from broker exception
|
/// Timeout on receiving from broker exception
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttTimeoutException : ApplicationException
|
public class MqttTimeoutException : Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -38,6 +36,14 @@ namespace uPLibrary.Networking.M2Mqtt
|
|||||||
/// <returns>Number of bytes received</returns>
|
/// <returns>Number of bytes received</returns>
|
||||||
int Receive(byte[] buffer);
|
int Receive(byte[] buffer);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Receive data from the network channel with a specified timeout
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">Data buffer for receiving data</param>
|
||||||
|
/// <param name="timeout">Timeout on receiving (in milliseconds)</param>
|
||||||
|
/// <returns>Number of bytes received</returns>
|
||||||
|
int Receive(byte[] buffer, int timeout);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Send data on the network channel to the broker
|
/// Send data on the network channel to the broker
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -54,5 +60,10 @@ namespace uPLibrary.Networking.M2Mqtt
|
|||||||
/// Connect to remote server
|
/// Connect to remote server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Connect();
|
void Connect();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Accept client connection
|
||||||
|
/// </summary>
|
||||||
|
void Accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
mqtt/M2Mqtt/Internal/InternalEvent.cs
Normal file
25
mqtt/M2Mqtt/Internal/InternalEvent.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt.Internal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Generic internal event for dispatching
|
||||||
|
/// </summary>
|
||||||
|
public abstract class InternalEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
51
mqtt/M2Mqtt/Internal/MsgInternalEvent.cs
Normal file
51
mqtt/M2Mqtt/Internal/MsgInternalEvent.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt.Internal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Internal event with a message
|
||||||
|
/// </summary>
|
||||||
|
public class MsgInternalEvent : InternalEvent
|
||||||
|
{
|
||||||
|
#region Properties ...
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Related message
|
||||||
|
/// </summary>
|
||||||
|
public MqttMsgBase Message
|
||||||
|
{
|
||||||
|
get { return this.msg; }
|
||||||
|
set { this.msg = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// related message
|
||||||
|
protected MqttMsgBase msg;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">Related message</param>
|
||||||
|
public MsgInternalEvent(MqttMsgBase msg)
|
||||||
|
{
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
mqtt/M2Mqtt/Internal/MsgPublishedInternalEvent.cs
Normal file
53
mqtt/M2Mqtt/Internal/MsgPublishedInternalEvent.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt.Internal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Internal event for a published message
|
||||||
|
/// </summary>
|
||||||
|
public class MsgPublishedInternalEvent : MsgInternalEvent
|
||||||
|
{
|
||||||
|
#region Properties...
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Message published (or failed due to retries)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPublished
|
||||||
|
{
|
||||||
|
get { return this.isPublished; }
|
||||||
|
internal set { this.isPublished = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// published flag
|
||||||
|
bool isPublished;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">Message published</param>
|
||||||
|
/// <param name="isPublished">Publish flag</param>
|
||||||
|
public MsgPublishedInternalEvent(MqttMsgBase msg, bool isPublished)
|
||||||
|
: base(msg)
|
||||||
|
{
|
||||||
|
this.isPublished = isPublished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,17 +19,19 @@
|
|||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>TRACE;DEBUG;SSL</DefineConstants>
|
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE;SSL</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
@ -42,6 +44,9 @@
|
|||||||
<Compile Include="Exceptions\MqttConnectionException.cs" />
|
<Compile Include="Exceptions\MqttConnectionException.cs" />
|
||||||
<Compile Include="Exceptions\MqttTimeoutException.cs" />
|
<Compile Include="Exceptions\MqttTimeoutException.cs" />
|
||||||
<Compile Include="IMqttNetworkChannel.cs" />
|
<Compile Include="IMqttNetworkChannel.cs" />
|
||||||
|
<Compile Include="Internal\InternalEvent.cs" />
|
||||||
|
<Compile Include="Internal\MsgInternalEvent.cs" />
|
||||||
|
<Compile Include="Internal\MsgPublishedInternalEvent.cs" />
|
||||||
<Compile Include="Messages\MqttMsgBase.cs" />
|
<Compile Include="Messages\MqttMsgBase.cs" />
|
||||||
<Compile Include="Messages\MqttMsgConnack.cs" />
|
<Compile Include="Messages\MqttMsgConnack.cs" />
|
||||||
<Compile Include="Messages\MqttMsgConnect.cs" />
|
<Compile Include="Messages\MqttMsgConnect.cs" />
|
||||||
@ -66,9 +71,15 @@
|
|||||||
<Compile Include="Messages\MqttMsgUnsubscribedEventArgs.cs" />
|
<Compile Include="Messages\MqttMsgUnsubscribedEventArgs.cs" />
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribeEventArgs.cs" />
|
<Compile Include="Messages\MqttMsgUnsubscribeEventArgs.cs" />
|
||||||
<Compile Include="MqttClient.cs" />
|
<Compile Include="MqttClient.cs" />
|
||||||
<Compile Include="MqttNetworkChannel.cs" />
|
<Compile Include="MqttSecurity.cs" />
|
||||||
|
<Compile Include="Net\Fx.cs" />
|
||||||
|
<Compile Include="Net\MqttNetworkChannel.cs" />
|
||||||
<Compile Include="MqttSettings.cs" />
|
<Compile Include="MqttSettings.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Session\MqttBrokerSession.cs" />
|
||||||
|
<Compile Include="Session\MqttClientSession.cs" />
|
||||||
|
<Compile Include="Session\MqttSession.cs" />
|
||||||
|
<Compile Include="Utility\Trace.cs" />
|
||||||
<Compile Include="Utility\QueueExtension.cs" />
|
<Compile Include="Utility\QueueExtension.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProductVersion>10.0.0</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectGuid>{9B706DEC-4CE7-4764-BDBE-8A5F855E5857}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<RootNamespace>uPLibrary.Networking.M2Mqtt</RootNamespace>
|
|
||||||
<AssemblyName>M2Mqtt</AssemblyName>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\Mono</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;SSL</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<ConsolePause>false</ConsolePause>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>none</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Release\Mono</OutputPath>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<ConsolePause>false</ConsolePause>
|
|
||||||
<DefineConstants>SSL</DefineConstants>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Exceptions\MqttClientException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttCommunicationException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttConnectionException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttTimeoutException.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgBase.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnack.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnectEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgContext.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgDisconnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingReq.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingResp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubcomp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublish.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrec.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="MqttClient.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="MqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="MqttSettings.cs" />
|
|
||||||
<Compile Include="Utility\QueueExtension.cs" />
|
|
||||||
<Compile Include="IMqttNetworkChannel.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
@ -1,106 +0,0 @@
|
|||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProductVersion>9.0.30729</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectGuid>{194FEA1B-E67F-4FC0-AC47-CD71F7F060CC}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>uPLibrary.Networking.M2Mqtt</RootNamespace>
|
|
||||||
<AssemblyName>M2Mqtt</AssemblyName>
|
|
||||||
<ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
|
||||||
<PlatformFamilyName>WindowsCE</PlatformFamilyName>
|
|
||||||
<PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID>
|
|
||||||
<OSVersion>5.0</OSVersion>
|
|
||||||
<DeployDirSuffix>M2MqttNetCf35</DeployDirSuffix>
|
|
||||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
|
||||||
<NativePlatformName>Windows CE</NativePlatformName>
|
|
||||||
<FormFactorID>
|
|
||||||
</FormFactorID>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\NetCf35\</OutputPath>
|
|
||||||
<DefineConstants>TRACE;DEBUG;WindowsCE,COMPACT_FRAMEWORK</DefineConstants>
|
|
||||||
<NoStdLib>true</NoStdLib>
|
|
||||||
<NoConfig>true</NoConfig>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\NetCf35\</OutputPath>
|
|
||||||
<DefineConstants>TRACE;WindowsCE,COMPACT_FRAMEWORK</DefineConstants>
|
|
||||||
<NoStdLib>true</NoStdLib>
|
|
||||||
<NoConfig>true</NoConfig>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="mscorlib" />
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Exceptions\MqttClientException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttCommunicationException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttConnectionException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttTimeoutException.cs" />
|
|
||||||
<Compile Include="IMqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgBase.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnack.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnectEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgContext.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgDisconnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingReq.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingResp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubcomp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublish.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrec.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="MqttClient.cs" />
|
|
||||||
<Compile Include="MqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="MqttSettings.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="Utility\QueueExtension.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
|
|
||||||
<ProjectExtensions>
|
|
||||||
<VisualStudio>
|
|
||||||
<FlavorProperties GUID="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}">
|
|
||||||
<HostingProcess disable="1" />
|
|
||||||
</FlavorProperties>
|
|
||||||
</VisualStudio>
|
|
||||||
</ProjectExtensions>
|
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
|
||||||
<Target Name="BeforeBuild">
|
|
||||||
</Target>
|
|
||||||
<Target Name="AfterBuild">
|
|
||||||
</Target>
|
|
||||||
-->
|
|
||||||
</Project>
|
|
@ -1,87 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{BB9B7FF4-6502-41AF-8851-5060B67645E8}</ProjectGuid>
|
|
||||||
<ProjectTypeGuids>{6AFDAB0D-95EF-424D-8A49-099ECD40B0FF};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>uPLibrary.Networking.M2Mqtt</RootNamespace>
|
|
||||||
<AssemblyName>M2Mqtt</AssemblyName>
|
|
||||||
<TargetFrameworkIdentifier>WindowsEmbeddedCompact</TargetFrameworkIdentifier>
|
|
||||||
<TargetFrameworkVersion>v3.9</TargetFrameworkVersion>
|
|
||||||
<TargetFrameworkTargetsVersion>v8.0</TargetFrameworkTargetsVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\NetCf39\</OutputPath>
|
|
||||||
<DefineConstants>TRACE;DEBUG;COMPACT_FRAMEWORK</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\NetCf39\</OutputPath>
|
|
||||||
<DefineConstants>TRACE;COMPACT_FRAMEWORK</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Exceptions\MqttClientException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttCommunicationException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttConnectionException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttTimeoutException.cs" />
|
|
||||||
<Compile Include="IMqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgBase.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnack.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnectEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgContext.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgDisconnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingReq.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingResp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubcomp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublish.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrec.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="MqttClient.cs" />
|
|
||||||
<Compile Include="MqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="MqttSettings.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="Utility\QueueExtension.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkTargetsVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
|
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
|
||||||
<Target Name="BeforeBuild">
|
|
||||||
</Target>
|
|
||||||
<Target Name="AfterBuild">
|
|
||||||
</Target>
|
|
||||||
-->
|
|
||||||
</Project>
|
|
@ -1,29 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if SSL && !WINDOWS_PHONE
|
|
||||||
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
using Microsoft.SPOT.Net.Security;
|
|
||||||
#else
|
|
||||||
using System.Net.Security;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
@ -38,6 +30,9 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
internal const byte MSG_TYPE_MASK = 0xF0;
|
internal const byte MSG_TYPE_MASK = 0xF0;
|
||||||
internal const byte MSG_TYPE_OFFSET = 0x04;
|
internal const byte MSG_TYPE_OFFSET = 0x04;
|
||||||
internal const byte MSG_TYPE_SIZE = 0x04;
|
internal const byte MSG_TYPE_SIZE = 0x04;
|
||||||
|
internal const byte MSG_FLAG_BITS_MASK = 0x0F; // [v3.1.1]
|
||||||
|
internal const byte MSG_FLAG_BITS_OFFSET = 0x00; // [v3.1.1]
|
||||||
|
internal const byte MSG_FLAG_BITS_SIZE = 0x04; // [v3.1.1]
|
||||||
internal const byte DUP_FLAG_MASK = 0x08;
|
internal const byte DUP_FLAG_MASK = 0x08;
|
||||||
internal const byte DUP_FLAG_OFFSET = 0x03;
|
internal const byte DUP_FLAG_OFFSET = 0x03;
|
||||||
internal const byte DUP_FLAG_SIZE = 0x01;
|
internal const byte DUP_FLAG_SIZE = 0x01;
|
||||||
@ -64,11 +59,30 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
internal const byte MQTT_MSG_PINGRESP_TYPE = 0x0D;
|
internal const byte MQTT_MSG_PINGRESP_TYPE = 0x0D;
|
||||||
internal const byte MQTT_MSG_DISCONNECT_TYPE = 0x0E;
|
internal const byte MQTT_MSG_DISCONNECT_TYPE = 0x0E;
|
||||||
|
|
||||||
|
// [v3.1.1] MQTT flag bits
|
||||||
|
internal const byte MQTT_MSG_CONNECT_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_CONNACK_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_PUBLISH_FLAG_BITS = 0x00; // just defined as 0x00 but depends on publish props (dup, qos, retain)
|
||||||
|
internal const byte MQTT_MSG_PUBACK_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_PUBREC_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_PUBREL_FLAG_BITS = 0x02;
|
||||||
|
internal const byte MQTT_MSG_PUBCOMP_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_SUBSCRIBE_FLAG_BITS = 0x02;
|
||||||
|
internal const byte MQTT_MSG_SUBACK_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_UNSUBSCRIBE_FLAG_BITS = 0x02;
|
||||||
|
internal const byte MQTT_MSG_UNSUBACK_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_PINGREQ_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_PINGRESP_FLAG_BITS = 0x00;
|
||||||
|
internal const byte MQTT_MSG_DISCONNECT_FLAG_BITS = 0x00;
|
||||||
|
|
||||||
// QOS levels
|
// QOS levels
|
||||||
public const byte QOS_LEVEL_AT_MOST_ONCE = 0x00;
|
public const byte QOS_LEVEL_AT_MOST_ONCE = 0x00;
|
||||||
public const byte QOS_LEVEL_AT_LEAST_ONCE = 0x01;
|
public const byte QOS_LEVEL_AT_LEAST_ONCE = 0x01;
|
||||||
public const byte QOS_LEVEL_EXACTLY_ONCE = 0x02;
|
public const byte QOS_LEVEL_EXACTLY_ONCE = 0x02;
|
||||||
|
|
||||||
|
// SUBSCRIBE QoS level granted failure [v3.1.1]
|
||||||
|
public const byte QOS_LEVEL_GRANTED_FAILURE = 0x80;
|
||||||
|
|
||||||
internal const ushort MAX_TOPIC_LENGTH = 65535;
|
internal const ushort MAX_TOPIC_LENGTH = 65535;
|
||||||
internal const ushort MIN_TOPIC_LENGTH = 1;
|
internal const ushort MIN_TOPIC_LENGTH = 1;
|
||||||
internal const byte MESSAGE_ID_SIZE = 2;
|
internal const byte MESSAGE_ID_SIZE = 2;
|
||||||
@ -113,6 +127,15 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
set { this.retain = value; }
|
set { this.retain = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Message identifier for the message
|
||||||
|
/// </summary>
|
||||||
|
public ushort MessageId
|
||||||
|
{
|
||||||
|
get { return this.messageId; }
|
||||||
|
set { this.messageId = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// message type
|
// message type
|
||||||
@ -123,12 +146,15 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
protected byte qosLevel;
|
protected byte qosLevel;
|
||||||
// retain flag
|
// retain flag
|
||||||
protected bool retain;
|
protected bool retain;
|
||||||
|
// message identifier
|
||||||
|
protected ushort messageId;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns message bytes rapresentation
|
/// Returns message bytes rapresentation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="protocolVersion">Protocol version</param>
|
||||||
/// <returns>Bytes rapresentation</returns>
|
/// <returns>Bytes rapresentation</returns>
|
||||||
public abstract byte[] GetBytes();
|
public abstract byte[] GetBytes(byte protocolVersion);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encode remaining length and insert it into message buffer
|
/// Encode remaining length and insert it into message buffer
|
||||||
@ -172,5 +198,78 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
} while ((digit & 128) != 0);
|
} while ((digit & 128) != 0);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TRACE
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a string representation of the message for tracing
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Message name</param>
|
||||||
|
/// <param name="fieldNames">Message fields name</param>
|
||||||
|
/// <param name="fieldValues">Message fields value</param>
|
||||||
|
/// <returns>String representation of the message</returns>
|
||||||
|
protected string GetTraceString(string name, object[] fieldNames, object[] fieldValues)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append(name);
|
||||||
|
|
||||||
|
if ((fieldNames != null) && (fieldValues != null))
|
||||||
|
{
|
||||||
|
sb.Append("(");
|
||||||
|
bool addComma = false;
|
||||||
|
for (int i = 0; i < fieldValues.Length; i++)
|
||||||
|
{
|
||||||
|
if (fieldValues[i] != null)
|
||||||
|
{
|
||||||
|
if (addComma)
|
||||||
|
{
|
||||||
|
sb.Append(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(fieldNames[i]);
|
||||||
|
sb.Append(":");
|
||||||
|
sb.Append(GetStringObject(fieldValues[i]));
|
||||||
|
addComma = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.Append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
object GetStringObject(object value)
|
||||||
|
{
|
||||||
|
byte[] binary = value as byte[];
|
||||||
|
if (binary != null)
|
||||||
|
{
|
||||||
|
string hexChars = "0123456789ABCDEF";
|
||||||
|
StringBuilder sb = new StringBuilder(binary.Length * 2);
|
||||||
|
for (int i = 0; i < binary.Length; ++i)
|
||||||
|
{
|
||||||
|
sb.Append(hexChars[binary[i] >> 4]);
|
||||||
|
sb.Append(hexChars[binary[i] & 0x0F]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
object[] list = value as object[];
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append('[');
|
||||||
|
for (int i = 0; i < list.Length; ++i)
|
||||||
|
{
|
||||||
|
if (i > 0) sb.Append(',');
|
||||||
|
sb.Append(list[i]);
|
||||||
|
}
|
||||||
|
sb.Append(']');
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
@ -37,6 +36,13 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
private const byte TOPIC_NAME_COMP_RESP_BYTE_OFFSET = 0;
|
private const byte TOPIC_NAME_COMP_RESP_BYTE_OFFSET = 0;
|
||||||
private const byte TOPIC_NAME_COMP_RESP_BYTE_SIZE = 1;
|
private const byte TOPIC_NAME_COMP_RESP_BYTE_SIZE = 1;
|
||||||
|
// [v3.1.1] connect acknowledge flags replace "old" topic name compression respone (not used in 3.1)
|
||||||
|
private const byte CONN_ACK_FLAGS_BYTE_OFFSET = 0;
|
||||||
|
private const byte CONN_ACK_FLAGS_BYTE_SIZE = 1;
|
||||||
|
// [v3.1.1] session present flag
|
||||||
|
private const byte SESSION_PRESENT_FLAG_MASK = 0x01;
|
||||||
|
private const byte SESSION_PRESENT_FLAG_OFFSET = 0x00;
|
||||||
|
private const byte SESSION_PRESENT_FLAG_SIZE = 0x01;
|
||||||
private const byte CONN_RETURN_CODE_BYTE_OFFSET = 1;
|
private const byte CONN_RETURN_CODE_BYTE_OFFSET = 1;
|
||||||
private const byte CONN_RETURN_CODE_BYTE_SIZE = 1;
|
private const byte CONN_RETURN_CODE_BYTE_SIZE = 1;
|
||||||
|
|
||||||
@ -44,6 +50,16 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
#region Properties...
|
#region Properties...
|
||||||
|
|
||||||
|
// [v3.1.1] session present flag
|
||||||
|
/// <summary>
|
||||||
|
/// Session present flag
|
||||||
|
/// </summary>
|
||||||
|
public bool SessionPresent
|
||||||
|
{
|
||||||
|
get { return this.sessionPresent; }
|
||||||
|
set { this.sessionPresent = value; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return Code
|
/// Return Code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -55,6 +71,9 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// [v3.1.1] session present flag
|
||||||
|
private bool sessionPresent;
|
||||||
|
|
||||||
// return code for CONNACK message
|
// return code for CONNACK message
|
||||||
private byte returnCode;
|
private byte returnCode;
|
||||||
|
|
||||||
@ -70,26 +89,39 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a CONNACK message
|
/// Parse bytes for a CONNACK message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>CONNACK message instance</returns>
|
/// <returns>CONNACK message instance</returns>
|
||||||
public static MqttMsgConnack Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgConnack Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
MqttMsgConnack msg = new MqttMsgConnack();
|
MqttMsgConnack msg = new MqttMsgConnack();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_CONNACK_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
|
|
||||||
// read bytes from socket...
|
// read bytes from socket...
|
||||||
channel.Receive(buffer);
|
channel.Receive(buffer);
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] ... set session present flag ...
|
||||||
|
msg.sessionPresent = (buffer[CONN_ACK_FLAGS_BYTE_OFFSET] & SESSION_PRESENT_FLAG_MASK) != 0x00;
|
||||||
|
}
|
||||||
// ...and set return code from broker
|
// ...and set return code from broker
|
||||||
msg.returnCode = buffer[CONN_RETURN_CODE_BYTE_OFFSET];
|
msg.returnCode = buffer[CONN_RETURN_CODE_BYTE_OFFSET];
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte ProtocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -98,8 +130,12 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
// topic name compression response and connect return code
|
if (ProtocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
varHeaderSize += (TOPIC_NAME_COMP_RESP_BYTE_SIZE + CONN_RETURN_CODE_BYTE_SIZE);
|
// flags byte and connect return code
|
||||||
|
varHeaderSize += (CONN_ACK_FLAGS_BYTE_SIZE + CONN_RETURN_CODE_BYTE_SIZE);
|
||||||
|
else
|
||||||
|
// topic name compression response and connect return code
|
||||||
|
varHeaderSize += (TOPIC_NAME_COMP_RESP_BYTE_SIZE + CONN_RETURN_CODE_BYTE_SIZE);
|
||||||
|
|
||||||
remainingLength += (varHeaderSize + payloadSize);
|
remainingLength += (varHeaderSize + payloadSize);
|
||||||
|
|
||||||
@ -119,19 +155,37 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index] = (byte)(MQTT_MSG_CONNACK_TYPE << MSG_TYPE_OFFSET);
|
if (ProtocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
index++;
|
buffer[index++] = (MQTT_MSG_CONNACK_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_CONNACK_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (byte)(MQTT_MSG_CONNACK_TYPE << MSG_TYPE_OFFSET);
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
|
|
||||||
// topic name compression response (reserved values. not used);
|
if (ProtocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
buffer[index++] = 0x00;
|
// [v3.1.1] session present flag
|
||||||
|
buffer[index++] = this.sessionPresent ? (byte)(1 << SESSION_PRESENT_FLAG_OFFSET) : (byte)0x00;
|
||||||
|
else
|
||||||
|
// topic name compression response (reserved values. not used);
|
||||||
|
buffer[index++] = 0x00;
|
||||||
|
|
||||||
// connect return code
|
// connect return code
|
||||||
buffer[index++] = this.returnCode;
|
buffer[index++] = this.returnCode;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"CONNACK",
|
||||||
|
new object[] { "returnCode" },
|
||||||
|
new object[] { this.returnCode });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -30,19 +28,22 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
#region Constants...
|
#region Constants...
|
||||||
|
|
||||||
// protocol name supported
|
// protocol name supported
|
||||||
internal const string PROTOCOL_NAME = "MQIsdp";
|
internal const string PROTOCOL_NAME_V3_1 = "MQIsdp";
|
||||||
|
internal const string PROTOCOL_NAME_V3_1_1 = "MQTT"; // [v.3.1.1]
|
||||||
// max length for client id
|
|
||||||
|
// max length for client id (removed in 3.1.1)
|
||||||
internal const int CLIENT_ID_MAX_LENGTH = 23;
|
internal const int CLIENT_ID_MAX_LENGTH = 23;
|
||||||
|
|
||||||
// variable header fields
|
// variable header fields
|
||||||
internal const byte PROTOCOL_NAME_LEN_SIZE = 2;
|
internal const byte PROTOCOL_NAME_LEN_SIZE = 2;
|
||||||
internal const byte PROTOCOL_NAME_SIZE = 6;
|
internal const byte PROTOCOL_NAME_V3_1_SIZE = 6;
|
||||||
internal const byte PROTOCOL_VERSION_NUMBER_SIZE = 1;
|
internal const byte PROTOCOL_NAME_V3_1_1_SIZE = 4; // [v.3.1.1]
|
||||||
|
internal const byte PROTOCOL_VERSION_SIZE = 1;
|
||||||
internal const byte CONNECT_FLAGS_SIZE = 1;
|
internal const byte CONNECT_FLAGS_SIZE = 1;
|
||||||
internal const byte KEEP_ALIVE_TIME_SIZE = 2;
|
internal const byte KEEP_ALIVE_TIME_SIZE = 2;
|
||||||
|
|
||||||
internal const byte PROTOCOL_VERSION = 0x03;
|
internal const byte PROTOCOL_VERSION_V3_1 = 0x03;
|
||||||
|
internal const byte PROTOCOL_VERSION_V3_1_1 = 0x04; // [v.3.1.1]
|
||||||
internal const ushort KEEP_ALIVE_PERIOD_DEFAULT = 60; // seconds
|
internal const ushort KEEP_ALIVE_PERIOD_DEFAULT = 60; // seconds
|
||||||
internal const ushort MAX_KEEP_ALIVE = 65535; // 16 bit
|
internal const ushort MAX_KEEP_ALIVE = 65535; // 16 bit
|
||||||
|
|
||||||
@ -65,6 +66,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
internal const byte CLEAN_SESSION_FLAG_MASK = 0x02;
|
internal const byte CLEAN_SESSION_FLAG_MASK = 0x02;
|
||||||
internal const byte CLEAN_SESSION_FLAG_OFFSET = 0x01;
|
internal const byte CLEAN_SESSION_FLAG_OFFSET = 0x01;
|
||||||
internal const byte CLEAN_SESSION_FLAG_SIZE = 0x01;
|
internal const byte CLEAN_SESSION_FLAG_SIZE = 0x01;
|
||||||
|
// [v.3.1.1] lsb (reserved) must be now 0
|
||||||
|
internal const byte RESERVED_FLAG_MASK = 0x01;
|
||||||
|
internal const byte RESERVED_FLAG_OFFSET = 0x00;
|
||||||
|
internal const byte RESERVED_FLAG_SIZE = 0x01;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -218,7 +223,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clientId">Client identifier</param>
|
/// <param name="clientId">Client identifier</param>
|
||||||
public MqttMsgConnect(string clientId) :
|
public MqttMsgConnect(string clientId) :
|
||||||
this(clientId, null, null, false, QOS_LEVEL_AT_LEAST_ONCE, false, null, null, true, KEEP_ALIVE_PERIOD_DEFAULT)
|
this(clientId, null, null, false, QOS_LEVEL_AT_LEAST_ONCE, false, null, null, true, KEEP_ALIVE_PERIOD_DEFAULT, PROTOCOL_VERSION_V3_1_1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,6 +240,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// <param name="willMessage">Will message</param>
|
/// <param name="willMessage">Will message</param>
|
||||||
/// <param name="cleanSession">Clean sessione flag</param>
|
/// <param name="cleanSession">Clean sessione flag</param>
|
||||||
/// <param name="keepAlivePeriod">Keep alive period</param>
|
/// <param name="keepAlivePeriod">Keep alive period</param>
|
||||||
|
/// <param name="protocolVersion">Protocol version</param>
|
||||||
public MqttMsgConnect(string clientId,
|
public MqttMsgConnect(string clientId,
|
||||||
string username,
|
string username,
|
||||||
string password,
|
string password,
|
||||||
@ -244,7 +250,8 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
string willTopic,
|
string willTopic,
|
||||||
string willMessage,
|
string willMessage,
|
||||||
bool cleanSession,
|
bool cleanSession,
|
||||||
ushort keepAlivePeriod
|
ushort keepAlivePeriod,
|
||||||
|
byte protocolVersion
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.type = MQTT_MSG_CONNECT_TYPE;
|
this.type = MQTT_MSG_CONNECT_TYPE;
|
||||||
@ -259,15 +266,19 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
this.willMessage = willMessage;
|
this.willMessage = willMessage;
|
||||||
this.cleanSession = cleanSession;
|
this.cleanSession = cleanSession;
|
||||||
this.keepAlivePeriod = keepAlivePeriod;
|
this.keepAlivePeriod = keepAlivePeriod;
|
||||||
|
// [v.3.1.1] added new protocol name and version
|
||||||
|
this.protocolVersion = protocolVersion;
|
||||||
|
this.protocolName = (this.protocolVersion == PROTOCOL_VERSION_V3_1_1) ? PROTOCOL_NAME_V3_1_1 : PROTOCOL_NAME_V3_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse bytes for a CONNECT message
|
/// Parse bytes for a CONNECT message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>CONNECT message instance</returns>
|
/// <returns>CONNECT message instance</returns>
|
||||||
public static MqttMsgConnect Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgConnect Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -302,11 +313,20 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
index += protNameUtf8Length;
|
index += protNameUtf8Length;
|
||||||
msg.protocolName = new String(Encoding.UTF8.GetChars(protNameUtf8));
|
msg.protocolName = new String(Encoding.UTF8.GetChars(protNameUtf8));
|
||||||
|
|
||||||
|
// [v3.1.1] wrong protocol name
|
||||||
|
if (!msg.protocolName.Equals(PROTOCOL_NAME_V3_1) && !msg.protocolName.Equals(PROTOCOL_NAME_V3_1_1))
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidProtocolName);
|
||||||
|
|
||||||
// protocol version
|
// protocol version
|
||||||
msg.protocolVersion = buffer[index];
|
msg.protocolVersion = buffer[index];
|
||||||
index += PROTOCOL_VERSION_NUMBER_SIZE;
|
index += PROTOCOL_VERSION_SIZE;
|
||||||
|
|
||||||
// connect flags
|
// connect flags
|
||||||
|
// [v3.1.1] check lsb (reserved) must be 0
|
||||||
|
if ((msg.protocolVersion == PROTOCOL_VERSION_V3_1_1) &&
|
||||||
|
((buffer[index] & RESERVED_FLAG_MASK) != 0x00))
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidConnectFlags);
|
||||||
|
|
||||||
isUsernameFlag = (buffer[index] & USERNAME_FLAG_MASK) != 0x00;
|
isUsernameFlag = (buffer[index] & USERNAME_FLAG_MASK) != 0x00;
|
||||||
isPasswordFlag = (buffer[index] & PASSWORD_FLAG_MASK) != 0x00;
|
isPasswordFlag = (buffer[index] & PASSWORD_FLAG_MASK) != 0x00;
|
||||||
msg.willRetain = (buffer[index] & WILL_RETAIN_FLAG_MASK) != 0x00;
|
msg.willRetain = (buffer[index] & WILL_RETAIN_FLAG_MASK) != 0x00;
|
||||||
@ -319,13 +339,16 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
msg.keepAlivePeriod = (ushort)((buffer[index++] << 8) & 0xFF00);
|
msg.keepAlivePeriod = (ushort)((buffer[index++] << 8) & 0xFF00);
|
||||||
msg.keepAlivePeriod |= buffer[index++];
|
msg.keepAlivePeriod |= buffer[index++];
|
||||||
|
|
||||||
// client identifier
|
// client identifier [v3.1.1] it may be zero bytes long (empty string)
|
||||||
clientIdUtf8Length = ((buffer[index++] << 8) & 0xFF00);
|
clientIdUtf8Length = ((buffer[index++] << 8) & 0xFF00);
|
||||||
clientIdUtf8Length |= buffer[index++];
|
clientIdUtf8Length |= buffer[index++];
|
||||||
clientIdUtf8 = new byte[clientIdUtf8Length];
|
clientIdUtf8 = new byte[clientIdUtf8Length];
|
||||||
Array.Copy(buffer, index, clientIdUtf8, 0, clientIdUtf8Length);
|
Array.Copy(buffer, index, clientIdUtf8, 0, clientIdUtf8Length);
|
||||||
index += clientIdUtf8Length;
|
index += clientIdUtf8Length;
|
||||||
msg.clientId = new String(Encoding.UTF8.GetChars(clientIdUtf8));
|
msg.clientId = new String(Encoding.UTF8.GetChars(clientIdUtf8));
|
||||||
|
// [v3.1.1] if client identifier is zero bytes long, clean session must be true
|
||||||
|
if ((msg.protocolVersion == PROTOCOL_VERSION_V3_1_1) && (clientIdUtf8Length == 0) && (!msg.cleanSession))
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidClientId);
|
||||||
|
|
||||||
// will topic and will message
|
// will topic and will message
|
||||||
if (msg.willFlag)
|
if (msg.willFlag)
|
||||||
@ -370,7 +393,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -380,21 +403,49 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
byte[] clientIdUtf8 = Encoding.UTF8.GetBytes(this.clientId);
|
byte[] clientIdUtf8 = Encoding.UTF8.GetBytes(this.clientId);
|
||||||
byte[] willTopicUtf8 = (this.willTopic != null) ? Encoding.UTF8.GetBytes(this.willTopic) : null;
|
byte[] willTopicUtf8 = (this.willFlag && (this.willTopic != null)) ? Encoding.UTF8.GetBytes(this.willTopic) : null;
|
||||||
byte[] willMessageUtf8 = (this.willMessage != null) ? Encoding.UTF8.GetBytes(this.willMessage) : null;
|
byte[] willMessageUtf8 = (this.willFlag && (this.willMessage != null)) ? Encoding.UTF8.GetBytes(this.willMessage) : null;
|
||||||
byte[] usernameUtf8 = (this.username != null) ? Encoding.UTF8.GetBytes(this.username) : null;
|
byte[] usernameUtf8 = ((this.username != null) && (this.username.Length > 0)) ? Encoding.UTF8.GetBytes(this.username) : null;
|
||||||
byte[] passwordUtf8 = (this.password != null) ? Encoding.UTF8.GetBytes(this.password) : null;
|
byte[] passwordUtf8 = ((this.password != null) && (this.password.Length > 0)) ? Encoding.UTF8.GetBytes(this.password) : null;
|
||||||
|
|
||||||
|
// [v3.1.1]
|
||||||
|
if (this.protocolVersion == PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// will flag set, will topic and will message MUST be present
|
||||||
|
if (this.willFlag && ((this.willQosLevel >= 0x03) ||
|
||||||
|
(willTopicUtf8 == null) || (willMessageUtf8 == null) ||
|
||||||
|
((willTopicUtf8 != null) && (willTopicUtf8.Length == 0)) ||
|
||||||
|
((willMessageUtf8 != null) && (willMessageUtf8.Length == 0))))
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.WillWrong);
|
||||||
|
// willflag not set, retain must be 0 and will topic and message MUST NOT be present
|
||||||
|
else if (!this.willFlag && ((this.willRetain) ||
|
||||||
|
(willTopicUtf8 != null) || (willMessageUtf8 != null) ||
|
||||||
|
((willTopicUtf8 != null) && (willTopicUtf8.Length != 0)) ||
|
||||||
|
((willMessageUtf8 != null) && (willMessageUtf8.Length != 0))))
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.WillWrong);
|
||||||
|
}
|
||||||
|
|
||||||
// will flag set but will topic wrong
|
|
||||||
if (this.willFlag && (willTopicUtf8.Length == 0))
|
|
||||||
throw new MqttClientException(MqttClientErrorCode.WillTopicWrong);
|
|
||||||
if (this.keepAlivePeriod > MAX_KEEP_ALIVE)
|
if (this.keepAlivePeriod > MAX_KEEP_ALIVE)
|
||||||
throw new MqttClientException(MqttClientErrorCode.KeepAliveWrong);
|
throw new MqttClientException(MqttClientErrorCode.KeepAliveWrong);
|
||||||
|
|
||||||
|
// check on will QoS Level
|
||||||
|
if ((this.willQosLevel < MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE) ||
|
||||||
|
(this.willQosLevel > MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE))
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.WillWrong);
|
||||||
|
|
||||||
// protocol name field size
|
// protocol name field size
|
||||||
varHeaderSize += (PROTOCOL_NAME_LEN_SIZE + PROTOCOL_NAME_SIZE);
|
// MQTT version 3.1
|
||||||
// protocol version number field size
|
if (this.protocolVersion == PROTOCOL_VERSION_V3_1)
|
||||||
varHeaderSize += PROTOCOL_VERSION_NUMBER_SIZE;
|
{
|
||||||
|
varHeaderSize += (PROTOCOL_NAME_LEN_SIZE + PROTOCOL_NAME_V3_1_SIZE);
|
||||||
|
}
|
||||||
|
// MQTT version 3.1.1
|
||||||
|
else
|
||||||
|
{
|
||||||
|
varHeaderSize += (PROTOCOL_NAME_LEN_SIZE + PROTOCOL_NAME_V3_1_1_SIZE);
|
||||||
|
}
|
||||||
|
// protocol level field size
|
||||||
|
varHeaderSize += PROTOCOL_VERSION_SIZE;
|
||||||
// connect flags field size
|
// connect flags field size
|
||||||
varHeaderSize += CONNECT_FLAGS_SIZE;
|
varHeaderSize += CONNECT_FLAGS_SIZE;
|
||||||
// keep alive timer field size
|
// keep alive timer field size
|
||||||
@ -429,30 +480,40 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index++] = (MQTT_MSG_CONNECT_TYPE << MSG_TYPE_OFFSET);
|
buffer[index++] = (MQTT_MSG_CONNECT_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_CONNECT_FLAG_BITS; // [v.3.1.1]
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
|
|
||||||
// protocol name
|
// protocol name
|
||||||
buffer[index++] = 0; // MSB protocol name size
|
buffer[index++] = 0; // MSB protocol name size
|
||||||
buffer[index++] = PROTOCOL_NAME_SIZE; // LSB protocol name size
|
// MQTT version 3.1
|
||||||
buffer[index++] = (byte)'M';
|
if (this.protocolVersion == PROTOCOL_VERSION_V3_1)
|
||||||
buffer[index++] = (byte)'Q';
|
{
|
||||||
buffer[index++] = (byte)'I';
|
buffer[index++] = PROTOCOL_NAME_V3_1_SIZE; // LSB protocol name size
|
||||||
buffer[index++] = (byte)'s';
|
Array.Copy(Encoding.UTF8.GetBytes(PROTOCOL_NAME_V3_1), 0, buffer, index, PROTOCOL_NAME_V3_1_SIZE);
|
||||||
buffer[index++] = (byte)'d';
|
index += PROTOCOL_NAME_V3_1_SIZE;
|
||||||
buffer[index++] = (byte)'p';
|
// protocol version
|
||||||
|
buffer[index++] = PROTOCOL_VERSION_V3_1;
|
||||||
// protocol version
|
}
|
||||||
buffer[index++] = PROTOCOL_VERSION;
|
// MQTT version 3.1.1
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer[index++] = PROTOCOL_NAME_V3_1_1_SIZE; // LSB protocol name size
|
||||||
|
Array.Copy(Encoding.UTF8.GetBytes(PROTOCOL_NAME_V3_1_1), 0, buffer, index, PROTOCOL_NAME_V3_1_1_SIZE);
|
||||||
|
index += PROTOCOL_NAME_V3_1_1_SIZE;
|
||||||
|
// protocol version
|
||||||
|
buffer[index++] = PROTOCOL_VERSION_V3_1_1;
|
||||||
|
}
|
||||||
|
|
||||||
// connect flags
|
// connect flags
|
||||||
byte connectFlags = 0x00;
|
byte connectFlags = 0x00;
|
||||||
connectFlags |= (this.username != null) ? (byte)(1 << USERNAME_FLAG_OFFSET) : (byte)0x00;
|
connectFlags |= (usernameUtf8 != null) ? (byte)(1 << USERNAME_FLAG_OFFSET) : (byte)0x00;
|
||||||
connectFlags |= (this.password != null) ? (byte)(1 << PASSWORD_FLAG_OFFSET) : (byte)0x00;
|
connectFlags |= (passwordUtf8 != null) ? (byte)(1 << PASSWORD_FLAG_OFFSET) : (byte)0x00;
|
||||||
connectFlags |= (this.willRetain) ? (byte)(1 << WILL_RETAIN_FLAG_OFFSET) : (byte)0x00;
|
connectFlags |= (this.willRetain) ? (byte)(1 << WILL_RETAIN_FLAG_OFFSET) : (byte)0x00;
|
||||||
connectFlags |= (byte)(this.willQosLevel << WILL_QOS_FLAG_OFFSET);
|
// only if will flag is set, we have to use will QoS level (otherwise is MUST be 0)
|
||||||
|
if (this.willFlag)
|
||||||
|
connectFlags |= (byte)(this.willQosLevel << WILL_QOS_FLAG_OFFSET);
|
||||||
connectFlags |= (this.willFlag) ? (byte)(1 << WILL_FLAG_OFFSET) : (byte)0x00;
|
connectFlags |= (this.willFlag) ? (byte)(1 << WILL_FLAG_OFFSET) : (byte)0x00;
|
||||||
connectFlags |= (this.cleanSession) ? (byte)(1 << CLEAN_SESSION_FLAG_OFFSET) : (byte)0x00;
|
connectFlags |= (this.cleanSession) ? (byte)(1 << CLEAN_SESSION_FLAG_OFFSET) : (byte)0x00;
|
||||||
buffer[index++] = connectFlags;
|
buffer[index++] = connectFlags;
|
||||||
@ -468,7 +529,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
index += clientIdUtf8.Length;
|
index += clientIdUtf8.Length;
|
||||||
|
|
||||||
// will topic
|
// will topic
|
||||||
if (this.willFlag && (this.willTopic != null))
|
if (this.willFlag && (willTopicUtf8 != null))
|
||||||
{
|
{
|
||||||
buffer[index++] = (byte)((willTopicUtf8.Length >> 8) & 0x00FF); // MSB
|
buffer[index++] = (byte)((willTopicUtf8.Length >> 8) & 0x00FF); // MSB
|
||||||
buffer[index++] = (byte)(willTopicUtf8.Length & 0x00FF); // LSB
|
buffer[index++] = (byte)(willTopicUtf8.Length & 0x00FF); // LSB
|
||||||
@ -477,7 +538,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
}
|
}
|
||||||
|
|
||||||
// will message
|
// will message
|
||||||
if (this.willFlag && (this.willMessage != null))
|
if (this.willFlag && (willMessageUtf8 != null))
|
||||||
{
|
{
|
||||||
buffer[index++] = (byte)((willMessageUtf8.Length >> 8) & 0x00FF); // MSB
|
buffer[index++] = (byte)((willMessageUtf8.Length >> 8) & 0x00FF); // MSB
|
||||||
buffer[index++] = (byte)(willMessageUtf8.Length & 0x00FF); // LSB
|
buffer[index++] = (byte)(willMessageUtf8.Length & 0x00FF); // LSB
|
||||||
@ -486,7 +547,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
}
|
}
|
||||||
|
|
||||||
// username
|
// username
|
||||||
if (this.username != null)
|
if (usernameUtf8 != null)
|
||||||
{
|
{
|
||||||
buffer[index++] = (byte)((usernameUtf8.Length >> 8) & 0x00FF); // MSB
|
buffer[index++] = (byte)((usernameUtf8.Length >> 8) & 0x00FF); // MSB
|
||||||
buffer[index++] = (byte)(usernameUtf8.Length & 0x00FF); // LSB
|
buffer[index++] = (byte)(usernameUtf8.Length & 0x00FF); // LSB
|
||||||
@ -495,7 +556,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
}
|
}
|
||||||
|
|
||||||
// password
|
// password
|
||||||
if (this.password != null)
|
if (passwordUtf8 != null)
|
||||||
{
|
{
|
||||||
buffer[index++] = (byte)((passwordUtf8.Length >> 8) & 0x00FF); // MSB
|
buffer[index++] = (byte)((passwordUtf8.Length >> 8) & 0x00FF); // MSB
|
||||||
buffer[index++] = (byte)(passwordUtf8.Length & 0x00FF); // LSB
|
buffer[index++] = (byte)(passwordUtf8.Length & 0x00FF); // LSB
|
||||||
@ -505,5 +566,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"CONNECT",
|
||||||
|
new object[] { "protocolName", "protocolVersion", "clientId", "willFlag", "willRetain", "willQosLevel", "willTopic", "willMessage", "username", "password", "cleanSession", "keepAlivePeriod" },
|
||||||
|
new object[] { this.protocolName, this.protocolVersion, this.clientId, this.willFlag, this.willRetain, this.willQosLevel, this.willTopic, this.willMessage, this.username, this.password, this.cleanSession, this.keepAlivePeriod });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -50,6 +48,14 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Attempt (for retry)
|
/// Attempt (for retry)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Attempt { get; set; }
|
public int Attempt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unique key
|
||||||
|
/// </summary>
|
||||||
|
public string Key
|
||||||
|
{
|
||||||
|
get { return this.Flow + "_" + this.Message.MessageId; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -128,6 +134,18 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
SendPuback,
|
SendPuback,
|
||||||
|
|
||||||
|
// [v3.1.1] SUBSCRIBE isn't "officially" QOS = 1
|
||||||
|
/// <summary>
|
||||||
|
/// Send SUBSCRIBE message
|
||||||
|
/// </summary>
|
||||||
|
SendSubscribe,
|
||||||
|
|
||||||
|
// [v3.1.1] UNSUBSCRIBE isn't "officially" QOS = 1
|
||||||
|
/// <summary>
|
||||||
|
/// Send UNSUBSCRIBE message
|
||||||
|
/// </summary>
|
||||||
|
SendUnsubscribe,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// (QOS = 1), SUBSCRIBE sent, wait for SUBACK
|
/// (QOS = 1), SUBSCRIBE sent, wait for SUBACK
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
@ -36,12 +35,20 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a DISCONNECT message
|
/// Parse bytes for a DISCONNECT message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>DISCONNECT message instance</returns>
|
/// <returns>DISCONNECT message instance</returns>
|
||||||
public static MqttMsgDisconnect Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgDisconnect Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
MqttMsgDisconnect msg = new MqttMsgDisconnect();
|
MqttMsgDisconnect msg = new MqttMsgDisconnect();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.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
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
// NOTE : remainingLength must be 0
|
// NOTE : remainingLength must be 0
|
||||||
@ -49,16 +56,31 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[2];
|
byte[] buffer = new byte[2];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index++] = (MQTT_MSG_DISCONNECT_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_DISCONNECT_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_DISCONNECT_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (MQTT_MSG_DISCONNECT_TYPE << MSG_TYPE_OFFSET);
|
||||||
buffer[index++] = 0x00;
|
buffer[index++] = 0x00;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"DISCONNECT",
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
@ -32,13 +31,16 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
this.type = MQTT_MSG_PINGREQ_TYPE;
|
this.type = MQTT_MSG_PINGREQ_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[2];
|
byte[] buffer = new byte[2];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index++] = (MQTT_MSG_PINGREQ_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_PINGREQ_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_PINGREQ_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (MQTT_MSG_PINGREQ_TYPE << MSG_TYPE_OFFSET);
|
||||||
buffer[index++] = 0x00;
|
buffer[index++] = 0x00;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
@ -48,17 +50,37 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a PINGREQ message
|
/// Parse bytes for a PINGREQ message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>PINGREQ message instance</returns>
|
/// <returns>PINGREQ message instance</returns>
|
||||||
public static MqttMsgPingReq Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgPingReq Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
MqttMsgPingReq msg = new MqttMsgPingReq();
|
MqttMsgPingReq msg = new MqttMsgPingReq();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_PINGREQ_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// already know remaininglength is zero (MQTT specification),
|
// already know remaininglength is zero (MQTT specification),
|
||||||
// so it isn't necessary to read other data from socket
|
// so it isn't necessary to read other data from socket
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"PINGREQ",
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
@ -37,12 +36,20 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a PINGRESP message
|
/// Parse bytes for a PINGRESP message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>PINGRESP message instance</returns>
|
/// <returns>PINGRESP message instance</returns>
|
||||||
public static MqttMsgPingResp Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgPingResp Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
MqttMsgPingResp msg = new MqttMsgPingResp();
|
MqttMsgPingResp msg = new MqttMsgPingResp();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_PINGRESP_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// already know remaininglength is zero (MQTT specification),
|
// already know remaininglength is zero (MQTT specification),
|
||||||
// so it isn't necessary to read other data from socket
|
// so it isn't necessary to read other data from socket
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
@ -50,16 +57,31 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[2];
|
byte[] buffer = new byte[2];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index++] = (MQTT_MSG_PINGRESP_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_PINGRESP_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_PINGRESP_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (MQTT_MSG_PINGRESP_TYPE << MSG_TYPE_OFFSET);
|
||||||
buffer[index++] = 0x00;
|
buffer[index++] = 0x00;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"PINGRESP",
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -23,23 +23,6 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttMsgPuback : MqttMsgBase
|
public class MqttMsgPuback : MqttMsgBase
|
||||||
{
|
{
|
||||||
#region Properties...
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier for the publish message
|
|
||||||
/// that is acknowledged
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
// message identifier
|
|
||||||
private ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -48,7 +31,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
this.type = MQTT_MSG_PUBACK_TYPE;
|
this.type = MQTT_MSG_PUBACK_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -78,7 +61,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index++] = (MQTT_MSG_PUBACK_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_PUBACK_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_PUBACK_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (MQTT_MSG_PUBACK_TYPE << MSG_TYPE_OFFSET);
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
@ -94,14 +80,22 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a PUBACK message
|
/// Parse bytes for a PUBACK message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>PUBACK message instance</returns>
|
/// <returns>PUBACK message instance</returns>
|
||||||
public static MqttMsgPuback Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgPuback Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
MqttMsgPuback msg = new MqttMsgPuback();
|
MqttMsgPuback msg = new MqttMsgPuback();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_PUBACK_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -115,5 +109,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"PUBACK",
|
||||||
|
new object[] { "messageId" },
|
||||||
|
new object[] { this.messageId });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -23,22 +23,6 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttMsgPubcomp : MqttMsgBase
|
public class MqttMsgPubcomp : MqttMsgBase
|
||||||
{
|
{
|
||||||
#region Properties...
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier for the acknowledged publish message
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
// message identifier
|
|
||||||
private ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,7 +31,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
this.type = MQTT_MSG_PUBCOMP_TYPE;
|
this.type = MQTT_MSG_PUBCOMP_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -77,7 +61,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index++] = (MQTT_MSG_PUBCOMP_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_PUBCOMP_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_PUBCOMP_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (MQTT_MSG_PUBCOMP_TYPE << MSG_TYPE_OFFSET);
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
@ -93,14 +80,22 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a PUBCOMP message
|
/// Parse bytes for a PUBCOMP message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>PUBCOMP message instance</returns>
|
/// <returns>PUBCOMP message instance</returns>
|
||||||
public static MqttMsgPubcomp Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgPubcomp Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
MqttMsgPubcomp msg = new MqttMsgPubcomp();
|
MqttMsgPubcomp msg = new MqttMsgPubcomp();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_PUBCOMP_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -114,5 +109,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"PUBCOMP",
|
||||||
|
new object[] { "messageId" },
|
||||||
|
new object[] { this.messageId });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -47,24 +45,13 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
set { this.message = value; }
|
set { this.message = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// message topic
|
// message topic
|
||||||
private string topic;
|
private string topic;
|
||||||
// message data
|
// message data
|
||||||
private byte[] message;
|
private byte[] message;
|
||||||
// message identifier
|
|
||||||
ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -107,7 +94,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
this.messageId = 0;
|
this.messageId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -124,6 +111,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
if ((this.topic.Length < MIN_TOPIC_LENGTH) || (this.topic.Length > MAX_TOPIC_LENGTH))
|
if ((this.topic.Length < MIN_TOPIC_LENGTH) || (this.topic.Length > MAX_TOPIC_LENGTH))
|
||||||
throw new MqttClientException(MqttClientErrorCode.TopicLength);
|
throw new MqttClientException(MqttClientErrorCode.TopicLength);
|
||||||
|
|
||||||
|
// check wrong QoS level (both bits can't be set 1)
|
||||||
|
if (this.qosLevel > QOS_LEVEL_EXACTLY_ONCE)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.QosNotAllowed);
|
||||||
|
|
||||||
byte[] topicUtf8 = Encoding.UTF8.GetBytes(this.topic);
|
byte[] topicUtf8 = Encoding.UTF8.GetBytes(this.topic);
|
||||||
|
|
||||||
// topic name
|
// topic name
|
||||||
@ -200,9 +191,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a PUBLISH message
|
/// Parse bytes for a PUBLISH message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>PUBLISH message instance</returns>
|
/// <returns>PUBLISH message instance</returns>
|
||||||
public static MqttMsgPublish Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgPublish Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -227,6 +219,9 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
// read QoS level from fixed header
|
// read QoS level from fixed header
|
||||||
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
||||||
|
// check wrong QoS level (both bits can't be set 1)
|
||||||
|
if (msg.qosLevel > QOS_LEVEL_EXACTLY_ONCE)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.QosNotAllowed);
|
||||||
// read DUP flag from fixed header
|
// read DUP flag from fixed header
|
||||||
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
||||||
// read retain flag from fixed header
|
// read retain flag from fixed header
|
||||||
@ -266,5 +261,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"PUBLISH",
|
||||||
|
new object[] { "messageId", "topic", "message" },
|
||||||
|
new object[] { this.messageId, this.topic, this.message });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
@ -40,18 +38,41 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
internal set { this.messageId = value; }
|
internal set { this.messageId = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Message published (or failed due to retries)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPublished
|
||||||
|
{
|
||||||
|
get { return this.isPublished; }
|
||||||
|
internal set { this.isPublished = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// message identifier
|
// message identifier
|
||||||
ushort messageId;
|
ushort messageId;
|
||||||
|
|
||||||
|
// published flag
|
||||||
|
bool isPublished;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor (published message)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="messageId">Message identifier published</param>
|
||||||
|
public MqttMsgPublishedEventArgs(ushort messageId)
|
||||||
|
: this(messageId, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="messageId">Message identifier published</param>
|
/// <param name="messageId">Message identifier</param>
|
||||||
public MqttMsgPublishedEventArgs(ushort messageId)
|
/// <param name="isPublished">Publish flag</param>
|
||||||
|
public MqttMsgPublishedEventArgs(ushort messageId, bool isPublished)
|
||||||
{
|
{
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
|
this.isPublished = isPublished;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -23,22 +23,6 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttMsgPubrec : MqttMsgBase
|
public class MqttMsgPubrec : MqttMsgBase
|
||||||
{
|
{
|
||||||
#region Properties...
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier for the acknowledged publish message
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
// message identifier
|
|
||||||
private ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,7 +31,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
this.type = MQTT_MSG_PUBREC_TYPE;
|
this.type = MQTT_MSG_PUBREC_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -77,7 +61,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index++] = (MQTT_MSG_PUBREC_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_PUBREC_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_PUBREC_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (MQTT_MSG_PUBREC_TYPE << MSG_TYPE_OFFSET);
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
@ -93,14 +80,22 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a PUBREC message
|
/// Parse bytes for a PUBREC message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>PUBREC message instance</returns>
|
/// <returns>PUBREC message instance</returns>
|
||||||
public static MqttMsgPubrec Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgPubrec Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
MqttMsgPubrec msg = new MqttMsgPubrec();
|
MqttMsgPubrec msg = new MqttMsgPubrec();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_PUBREC_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -114,5 +109,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"PUBREC",
|
||||||
|
new object[] { "messageId" },
|
||||||
|
new object[] { this.messageId });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -23,33 +23,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttMsgPubrel : MqttMsgBase
|
public class MqttMsgPubrel : MqttMsgBase
|
||||||
{
|
{
|
||||||
#region Properties...
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier for the acknowledged publish message
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
// message identifier
|
|
||||||
private ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MqttMsgPubrel()
|
public MqttMsgPubrel()
|
||||||
{
|
{
|
||||||
this.type = MQTT_MSG_PUBREL_TYPE;
|
this.type = MQTT_MSG_PUBREL_TYPE;
|
||||||
// PUBREL message use QoS Level 1
|
// PUBREL message use QoS Level 1 (not "officially" in 3.1.1)
|
||||||
this.qosLevel = QOS_LEVEL_AT_LEAST_ONCE;
|
this.qosLevel = QOS_LEVEL_AT_LEAST_ONCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -79,10 +63,15 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index] = (byte)((MQTT_MSG_PUBREL_TYPE << MSG_TYPE_OFFSET) |
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_PUBREL_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_PUBREL_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer[index] = (byte)((MQTT_MSG_PUBREL_TYPE << MSG_TYPE_OFFSET) |
|
||||||
(this.qosLevel << QOS_LEVEL_OFFSET));
|
(this.qosLevel << QOS_LEVEL_OFFSET));
|
||||||
buffer[index] |= this.dupFlag ? (byte)(1 << DUP_FLAG_OFFSET) : (byte)0x00;
|
buffer[index] |= this.dupFlag ? (byte)(1 << DUP_FLAG_OFFSET) : (byte)0x00;
|
||||||
index++;
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
@ -98,14 +87,22 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a PUBREL message
|
/// Parse bytes for a PUBREL message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>PUBREL message instance</returns>
|
/// <returns>PUBREL message instance</returns>
|
||||||
public static MqttMsgPubrel Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgPubrel Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
MqttMsgPubrel msg = new MqttMsgPubrel();
|
MqttMsgPubrel msg = new MqttMsgPubrel();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_PUBREL_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -113,10 +110,15 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
// read bytes from socket...
|
// read bytes from socket...
|
||||||
channel.Receive(buffer);
|
channel.Receive(buffer);
|
||||||
|
|
||||||
// read QoS level from fixed header (would be QoS Level 1)
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1)
|
||||||
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
{
|
||||||
// read DUP flag from fixed header
|
// only 3.1.0
|
||||||
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
|
||||||
|
// read QoS level from fixed header (would be QoS Level 1)
|
||||||
|
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
||||||
|
// read DUP flag from fixed header
|
||||||
|
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
||||||
|
}
|
||||||
|
|
||||||
// message id
|
// message id
|
||||||
msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00);
|
msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00);
|
||||||
@ -124,5 +126,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"PUBREL",
|
||||||
|
new object[] { "messageId" },
|
||||||
|
new object[] { this.messageId });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
@ -27,16 +26,6 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
{
|
{
|
||||||
#region Properties...
|
#region Properties...
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier for the subscribe message
|
|
||||||
/// that is acknowledged
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of granted QOS Levels
|
/// List of granted QOS Levels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -48,8 +37,6 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// message identifier
|
|
||||||
private ushort messageId;
|
|
||||||
// granted QOS levels
|
// granted QOS levels
|
||||||
byte[] grantedQosLevels;
|
byte[] grantedQosLevels;
|
||||||
|
|
||||||
@ -65,14 +52,22 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a SUBACK message
|
/// Parse bytes for a SUBACK message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>SUBACK message instance</returns>
|
/// <returns>SUBACK message instance</returns>
|
||||||
public static MqttMsgSuback Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgSuback Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
MqttMsgSuback msg = new MqttMsgSuback();
|
MqttMsgSuback msg = new MqttMsgSuback();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_SUBACK_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -95,7 +90,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -131,9 +126,11 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index] = (byte)(MQTT_MSG_SUBACK_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
index++;
|
buffer[index++] = (MQTT_MSG_SUBACK_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_SUBACK_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (byte)(MQTT_MSG_SUBACK_TYPE << MSG_TYPE_OFFSET);
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
|
|
||||||
@ -149,5 +146,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"SUBACK",
|
||||||
|
new object[] { "messageId", "grantedQosLevels" },
|
||||||
|
new object[] { this.messageId, this.grantedQosLevels });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -52,24 +50,13 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
set { this.qosLevels = value; }
|
set { this.qosLevels = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// topics to subscribe
|
// topics to subscribe
|
||||||
string[] topics;
|
string[] topics;
|
||||||
// QOS levels related to topics
|
// QOS levels related to topics
|
||||||
byte[] qosLevels;
|
byte[] qosLevels;
|
||||||
// message identifier
|
|
||||||
ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -90,7 +77,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
this.topics = topics;
|
this.topics = topics;
|
||||||
this.qosLevels = qosLevels;
|
this.qosLevels = qosLevels;
|
||||||
|
|
||||||
// SUBSCRIBE message uses QoS Level 1
|
// SUBSCRIBE message uses QoS Level 1 (not "officially" in 3.1.1)
|
||||||
this.qosLevel = QOS_LEVEL_AT_LEAST_ONCE;
|
this.qosLevel = QOS_LEVEL_AT_LEAST_ONCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,9 +85,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a SUBSCRIBE message
|
/// Parse bytes for a SUBSCRIBE message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>SUBSCRIBE message instance</returns>
|
/// <returns>SUBSCRIBE message instance</returns>
|
||||||
public static MqttMsgSubscribe Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgSubscribe Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -108,6 +96,13 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
int topicUtf8Length;
|
int topicUtf8Length;
|
||||||
MqttMsgSubscribe msg = new MqttMsgSubscribe();
|
MqttMsgSubscribe msg = new MqttMsgSubscribe();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_SUBSCRIBE_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -115,12 +110,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
// read bytes from socket...
|
// read bytes from socket...
|
||||||
int received = channel.Receive(buffer);
|
int received = channel.Receive(buffer);
|
||||||
|
|
||||||
// read QoS level from fixed header
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1)
|
||||||
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
{
|
||||||
// read DUP flag from fixed header
|
// only 3.1.0
|
||||||
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
|
||||||
// retain flag not used
|
// read QoS level from fixed header
|
||||||
msg.retain = false;
|
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
||||||
|
// read DUP flag from fixed header
|
||||||
|
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
||||||
|
// retain flag not used
|
||||||
|
msg.retain = false;
|
||||||
|
}
|
||||||
|
|
||||||
// message id
|
// message id
|
||||||
msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00);
|
msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00);
|
||||||
@ -165,7 +165,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -222,11 +222,16 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index] = (byte)((MQTT_MSG_SUBSCRIBE_TYPE << MSG_TYPE_OFFSET) |
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_SUBSCRIBE_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_SUBSCRIBE_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer[index] = (byte)((MQTT_MSG_SUBSCRIBE_TYPE << MSG_TYPE_OFFSET) |
|
||||||
(this.qosLevel << QOS_LEVEL_OFFSET));
|
(this.qosLevel << QOS_LEVEL_OFFSET));
|
||||||
buffer[index] |= this.dupFlag ? (byte)(1 << DUP_FLAG_OFFSET) : (byte)0x00;
|
buffer[index] |= this.dupFlag ? (byte)(1 << DUP_FLAG_OFFSET) : (byte)0x00;
|
||||||
index++;
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
|
|
||||||
@ -251,5 +256,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"SUBSCRIBE",
|
||||||
|
new object[] { "messageId", "topics", "qosLevels" },
|
||||||
|
new object[] { this.messageId, this.topics, this.qosLevels });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Exceptions;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt.Messages
|
namespace uPLibrary.Networking.M2Mqtt.Messages
|
||||||
{
|
{
|
||||||
@ -25,23 +24,6 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MqttMsgUnsuback : MqttMsgBase
|
public class MqttMsgUnsuback : MqttMsgBase
|
||||||
{
|
{
|
||||||
#region Properties...
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier for the unsubscribe message
|
|
||||||
/// that is acknowledged
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
// message identifier
|
|
||||||
private ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -54,14 +36,22 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a UNSUBACK message
|
/// Parse bytes for a UNSUBACK message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>UNSUBACK message instance</returns>
|
/// <returns>UNSUBACK message instance</returns>
|
||||||
public static MqttMsgUnsuback Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgUnsuback Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
MqttMsgUnsuback msg = new MqttMsgUnsuback();
|
MqttMsgUnsuback msg = new MqttMsgUnsuback();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_UNSUBACK_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -76,7 +66,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -106,9 +96,11 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index] = (byte)(MQTT_MSG_UNSUBACK_TYPE << MSG_TYPE_OFFSET);
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
index++;
|
buffer[index++] = (MQTT_MSG_UNSUBACK_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_UNSUBACK_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
buffer[index++] = (byte)(MQTT_MSG_UNSUBACK_TYPE << MSG_TYPE_OFFSET);
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
|
|
||||||
@ -118,5 +110,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"UNSUBACK",
|
||||||
|
new object[] { "messageId" },
|
||||||
|
new object[] { this.messageId });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -43,22 +41,11 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
set { this.topics = value; }
|
set { this.topics = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message identifier
|
|
||||||
/// </summary>
|
|
||||||
public ushort MessageId
|
|
||||||
{
|
|
||||||
get { return this.messageId; }
|
|
||||||
set { this.messageId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// topics to unsubscribe
|
// topics to unsubscribe
|
||||||
string[] topics;
|
string[] topics;
|
||||||
// message identifier
|
|
||||||
ushort messageId;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -77,7 +64,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
this.topics = topics;
|
this.topics = topics;
|
||||||
|
|
||||||
// UNSUBSCRIBE message uses QoS Level 1
|
// UNSUBSCRIBE message uses QoS Level 1 (not "officially" in 3.1.1)
|
||||||
this.qosLevel = QOS_LEVEL_AT_LEAST_ONCE;
|
this.qosLevel = QOS_LEVEL_AT_LEAST_ONCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,9 +72,10 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
/// Parse bytes for a UNSUBSCRIBE message
|
/// Parse bytes for a UNSUBSCRIBE message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
/// <param name="fixedHeaderFirstByte">First fixed header byte</param>
|
||||||
|
/// <param name="protocolVersion">Protocol Version</param>
|
||||||
/// <param name="channel">Channel connected to the broker</param>
|
/// <param name="channel">Channel connected to the broker</param>
|
||||||
/// <returns>UNSUBSCRIBE message instance</returns>
|
/// <returns>UNSUBSCRIBE message instance</returns>
|
||||||
public static MqttMsgUnsubscribe Parse(byte fixedHeaderFirstByte, IMqttNetworkChannel channel)
|
public static MqttMsgUnsubscribe Parse(byte fixedHeaderFirstByte, byte protocolVersion, IMqttNetworkChannel channel)
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -95,6 +83,13 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
int topicUtf8Length;
|
int topicUtf8Length;
|
||||||
MqttMsgUnsubscribe msg = new MqttMsgUnsubscribe();
|
MqttMsgUnsubscribe msg = new MqttMsgUnsubscribe();
|
||||||
|
|
||||||
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
{
|
||||||
|
// [v3.1.1] check flag bits
|
||||||
|
if ((fixedHeaderFirstByte & MSG_FLAG_BITS_MASK) != MQTT_MSG_UNSUBSCRIBE_FLAG_BITS)
|
||||||
|
throw new MqttClientException(MqttClientErrorCode.InvalidFlagBits);
|
||||||
|
}
|
||||||
|
|
||||||
// get remaining length and allocate buffer
|
// get remaining length and allocate buffer
|
||||||
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
int remainingLength = MqttMsgBase.decodeRemainingLength(channel);
|
||||||
buffer = new byte[remainingLength];
|
buffer = new byte[remainingLength];
|
||||||
@ -102,12 +97,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
// read bytes from socket...
|
// read bytes from socket...
|
||||||
int received = channel.Receive(buffer);
|
int received = channel.Receive(buffer);
|
||||||
|
|
||||||
// read QoS level from fixed header
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1)
|
||||||
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
{
|
||||||
// read DUP flag from fixed header
|
// only 3.1.0
|
||||||
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
|
||||||
// retain flag not used
|
// read QoS level from fixed header
|
||||||
msg.retain = false;
|
msg.qosLevel = (byte)((fixedHeaderFirstByte & QOS_LEVEL_MASK) >> QOS_LEVEL_OFFSET);
|
||||||
|
// read DUP flag from fixed header
|
||||||
|
msg.dupFlag = (((fixedHeaderFirstByte & DUP_FLAG_MASK) >> DUP_FLAG_OFFSET) == 0x01);
|
||||||
|
// retain flag not used
|
||||||
|
msg.retain = false;
|
||||||
|
}
|
||||||
|
|
||||||
// message id
|
// message id
|
||||||
msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00);
|
msg.messageId = (ushort)((buffer[index++] << 8) & 0xFF00);
|
||||||
@ -144,7 +144,7 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetBytes()
|
public override byte[] GetBytes(byte protocolVersion)
|
||||||
{
|
{
|
||||||
int fixedHeaderSize = 0;
|
int fixedHeaderSize = 0;
|
||||||
int varHeaderSize = 0;
|
int varHeaderSize = 0;
|
||||||
@ -192,11 +192,16 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
buffer = new byte[fixedHeaderSize + varHeaderSize + payloadSize];
|
||||||
|
|
||||||
// first fixed header byte
|
// first fixed header byte
|
||||||
buffer[index] = (byte)((MQTT_MSG_UNSUBSCRIBE_TYPE << MSG_TYPE_OFFSET) |
|
if (protocolVersion == MqttMsgConnect.PROTOCOL_VERSION_V3_1_1)
|
||||||
|
buffer[index++] = (MQTT_MSG_UNSUBSCRIBE_TYPE << MSG_TYPE_OFFSET) | MQTT_MSG_UNSUBSCRIBE_FLAG_BITS; // [v.3.1.1]
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer[index] = (byte)((MQTT_MSG_UNSUBSCRIBE_TYPE << MSG_TYPE_OFFSET) |
|
||||||
(this.qosLevel << QOS_LEVEL_OFFSET));
|
(this.qosLevel << QOS_LEVEL_OFFSET));
|
||||||
buffer[index] |= this.dupFlag ? (byte)(1 << DUP_FLAG_OFFSET) : (byte)0x00;
|
buffer[index] |= this.dupFlag ? (byte)(1 << DUP_FLAG_OFFSET) : (byte)0x00;
|
||||||
index++;
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
// encode remaining length
|
// encode remaining length
|
||||||
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
index = this.encodeRemainingLength(remainingLength, buffer, index);
|
||||||
|
|
||||||
@ -218,5 +223,17 @@ namespace uPLibrary.Networking.M2Mqtt.Messages
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
#if TRACE
|
||||||
|
return this.GetTraceString(
|
||||||
|
"UNSUBSCRIBE",
|
||||||
|
new object[] { "messageId", "topics" },
|
||||||
|
new object[] { this.messageId, this.topics });
|
||||||
|
#else
|
||||||
|
return base.ToString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,272 +0,0 @@
|
|||||||
/*
|
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if SSL
|
|
||||||
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
using Microsoft.SPOT.Net.Security;
|
|
||||||
#else
|
|
||||||
using System.Net.Security;
|
|
||||||
using System.Security.Authentication;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Net;
|
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Channel to communicate over the network
|
|
||||||
/// </summary>
|
|
||||||
public class MqttNetworkChannel : IMqttNetworkChannel
|
|
||||||
{
|
|
||||||
// remote host information
|
|
||||||
private string remoteHostName;
|
|
||||||
private IPAddress remoteIpAddress;
|
|
||||||
private int remotePort;
|
|
||||||
|
|
||||||
// socket for communication
|
|
||||||
private Socket socket;
|
|
||||||
// using SSL
|
|
||||||
private bool secure;
|
|
||||||
|
|
||||||
// CA certificate
|
|
||||||
private X509Certificate caCert;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remote host name
|
|
||||||
/// </summary>
|
|
||||||
public string RemoteHostName { get { return this.remoteHostName; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remote IP address
|
|
||||||
/// </summary>
|
|
||||||
public IPAddress RemoteIpAddress { get { return this.remoteIpAddress; } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remote port
|
|
||||||
/// </summary>
|
|
||||||
public int RemotePort { get { return this.remotePort; } }
|
|
||||||
|
|
||||||
#if SSL
|
|
||||||
// SSL stream
|
|
||||||
private SslStream sslStream;
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
private NetworkStream netStream;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Data available on the channel
|
|
||||||
/// </summary>
|
|
||||||
public bool DataAvailable
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
#if SSL
|
|
||||||
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
if (secure)
|
|
||||||
return this.sslStream.DataAvailable;
|
|
||||||
else
|
|
||||||
return (this.socket.Available > 0);
|
|
||||||
#else
|
|
||||||
if (secure)
|
|
||||||
return this.netStream.DataAvailable;
|
|
||||||
else
|
|
||||||
return (this.socket.Available > 0);
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
return (this.socket.Available > 0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="socket">Socket opened with the client</param>
|
|
||||||
public MqttNetworkChannel(Socket socket)
|
|
||||||
{
|
|
||||||
this.socket = socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="remoteHostName">Remote Host name</param>
|
|
||||||
/// <param name="remoteIpAddress">Remote IP address</param>
|
|
||||||
/// <param name="remotePort">Remote port</param>
|
|
||||||
public MqttNetworkChannel(string remoteHostName, IPAddress remoteIpAddress, int remotePort) :
|
|
||||||
this(remoteHostName, remoteIpAddress, remotePort, false, null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="remoteHostName">Remote Host name</param>
|
|
||||||
/// <param name="remoteIpAddress">Remote IP address</param>
|
|
||||||
/// <param name="remotePort">Remote port</param>
|
|
||||||
/// <param name="secure">Using SSL</param>
|
|
||||||
/// <param name="caCert">CA certificate</param>
|
|
||||||
public MqttNetworkChannel(string remoteHostName, IPAddress remoteIpAddress, int remotePort, bool secure, X509Certificate caCert)
|
|
||||||
{
|
|
||||||
this.remoteHostName = remoteHostName;
|
|
||||||
this.remoteIpAddress = remoteIpAddress;
|
|
||||||
this.remotePort = remotePort;
|
|
||||||
this.secure = secure;
|
|
||||||
this.caCert = caCert;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Connect to remote server
|
|
||||||
/// </summary>
|
|
||||||
public void Connect()
|
|
||||||
{
|
|
||||||
this.socket = new Socket(IPAddressUtility.GetAddressFamily(this.remoteIpAddress), SocketType.Stream, ProtocolType.Tcp);
|
|
||||||
// try connection to the broker
|
|
||||||
this.socket.Connect(new IPEndPoint(this.remoteIpAddress, this.remotePort));
|
|
||||||
|
|
||||||
#if SSL
|
|
||||||
// secure channel requested
|
|
||||||
if (secure)
|
|
||||||
{
|
|
||||||
// create SSL stream
|
|
||||||
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
this.sslStream = new SslStream(this.socket);
|
|
||||||
#else
|
|
||||||
this.netStream = new NetworkStream(this.socket);
|
|
||||||
this.sslStream = new SslStream(this.netStream);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// server authentication (SSL/TLS handshake)
|
|
||||||
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
this.sslStream.AuthenticateAsClient(this.remoteHostName,
|
|
||||||
null,
|
|
||||||
new X509Certificate[] { this.caCert },
|
|
||||||
SslVerification.CertificateRequired,
|
|
||||||
SslProtocols.TLSv1);
|
|
||||||
#else
|
|
||||||
this.sslStream.AuthenticateAsClient(this.remoteHostName,
|
|
||||||
new X509CertificateCollection(new X509Certificate[] { this.caCert }),
|
|
||||||
SslProtocols.Tls, false);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Send data on the network channel
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="buffer">Data buffer to send</param>
|
|
||||||
/// <returns>Number of byte sent</returns>
|
|
||||||
public int Send(byte[] buffer)
|
|
||||||
{
|
|
||||||
#if SSL
|
|
||||||
if (this.secure)
|
|
||||||
{
|
|
||||||
this.sslStream.Write(buffer, 0, buffer.Length);
|
|
||||||
return buffer.Length;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return this.socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
|
|
||||||
#else
|
|
||||||
return this.socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Receive data from the network
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="buffer">Data buffer for receiving data</param>
|
|
||||||
/// <returns>Number of bytes received</returns>
|
|
||||||
public int Receive(byte[] buffer)
|
|
||||||
{
|
|
||||||
#if SSL
|
|
||||||
if (this.secure)
|
|
||||||
{
|
|
||||||
// read all data needed (until fill buffer)
|
|
||||||
int idx = 0;
|
|
||||||
while (idx < buffer.Length)
|
|
||||||
{
|
|
||||||
idx += this.sslStream.Read(buffer, idx, buffer.Length - idx);
|
|
||||||
}
|
|
||||||
return buffer.Length;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// read all data needed (until fill buffer)
|
|
||||||
int idx = 0;
|
|
||||||
while (idx < buffer.Length)
|
|
||||||
{
|
|
||||||
idx += this.socket.Receive(buffer, idx, buffer.Length - idx, SocketFlags.None);
|
|
||||||
}
|
|
||||||
return buffer.Length;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// read all data needed (until fill buffer)
|
|
||||||
int idx = 0;
|
|
||||||
while (idx < buffer.Length)
|
|
||||||
{
|
|
||||||
idx += this.socket.Receive(buffer, idx, buffer.Length - idx, SocketFlags.None);
|
|
||||||
}
|
|
||||||
return buffer.Length;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Close the network channel
|
|
||||||
/// </summary>
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
#if SSL
|
|
||||||
if (this.secure)
|
|
||||||
{
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
this.netStream.Close();
|
|
||||||
#endif
|
|
||||||
this.sslStream.Close();
|
|
||||||
}
|
|
||||||
this.socket.Close();
|
|
||||||
#else
|
|
||||||
this.socket.Close();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IPAddress Utility class
|
|
||||||
/// </summary>
|
|
||||||
public static class IPAddressUtility
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Return AddressFamily for the IP address
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ipAddress">IP address to check</param>
|
|
||||||
/// <returns>Address family</returns>
|
|
||||||
public static AddressFamily GetAddressFamily(IPAddress ipAddress)
|
|
||||||
{
|
|
||||||
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
|
||||||
return ipAddress.AddressFamily;
|
|
||||||
#else
|
|
||||||
return (ipAddress.ToString().IndexOf(':') != -1) ?
|
|
||||||
AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
30
mqtt/M2Mqtt/MqttSecurity.cs
Normal file
30
mqtt/M2Mqtt/MqttSecurity.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Supported SSL/TLS protocol versions
|
||||||
|
/// </summary>
|
||||||
|
public enum MqttSslProtocols
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
SSLv3,
|
||||||
|
TLSv1_0,
|
||||||
|
TLSv1_1,
|
||||||
|
TLSv1_2
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
@ -27,14 +25,16 @@ namespace uPLibrary.Networking.M2Mqtt
|
|||||||
public const int MQTT_BROKER_DEFAULT_PORT = 1883;
|
public const int MQTT_BROKER_DEFAULT_PORT = 1883;
|
||||||
public const int MQTT_BROKER_DEFAULT_SSL_PORT = 8883;
|
public const int MQTT_BROKER_DEFAULT_SSL_PORT = 8883;
|
||||||
// default timeout on receiving from client
|
// default timeout on receiving from client
|
||||||
public const int MQTT_DEFAULT_TIMEOUT = 25000;
|
public const int MQTT_DEFAULT_TIMEOUT = 30000;
|
||||||
// max publish, subscribe and unsubscribe retry for QoS Level 1 or 2
|
// max publish, subscribe and unsubscribe retry for QoS Level 1 or 2
|
||||||
public const int MQTT_ATTEMPTS_RETRY = 3;
|
public const int MQTT_ATTEMPTS_RETRY = 3;
|
||||||
// delay for retry publish, subscribe and unsubscribe for QoS Level 1 or 2
|
// delay for retry publish, subscribe and unsubscribe for QoS Level 1 or 2
|
||||||
public const int MQTT_DELAY_RETRY = 10000;
|
public const int MQTT_DELAY_RETRY = 10000;
|
||||||
// broker need to receive the first message (CONNECT)
|
// broker need to receive the first message (CONNECT)
|
||||||
// within a reasonable amount of time after TCP/IP connection
|
// within a reasonable amount of time after TCP/IP connection
|
||||||
public const int MQTT_CONNECT_TIMEOUT = 25000;
|
public const int MQTT_CONNECT_TIMEOUT = 30000;
|
||||||
|
// default inflight queue size
|
||||||
|
public const int MQTT_MAX_INFLIGHT_QUEUE_SIZE = int.MaxValue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Listening connection port
|
/// Listening connection port
|
||||||
@ -66,6 +66,11 @@ namespace uPLibrary.Networking.M2Mqtt
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int DelayOnRetry { get; internal set; }
|
public int DelayOnRetry { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Inflight queue size
|
||||||
|
/// </summary>
|
||||||
|
public int InflightQueueSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Singleton instance of settings
|
/// Singleton instance of settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -93,6 +98,7 @@ namespace uPLibrary.Networking.M2Mqtt
|
|||||||
this.AttemptsOnRetry = MQTT_ATTEMPTS_RETRY;
|
this.AttemptsOnRetry = MQTT_ATTEMPTS_RETRY;
|
||||||
this.DelayOnRetry = MQTT_DELAY_RETRY;
|
this.DelayOnRetry = MQTT_DELAY_RETRY;
|
||||||
this.TimeoutOnConnection = MQTT_CONNECT_TIMEOUT;
|
this.TimeoutOnConnection = MQTT_CONNECT_TIMEOUT;
|
||||||
|
this.InflightQueueSize = MQTT_MAX_INFLIGHT_QUEUE_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
mqtt/M2Mqtt/Net/Fx.cs
Normal file
36
mqtt/M2Mqtt/Net/Fx.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Support methods fos specific framework
|
||||||
|
/// </summary>
|
||||||
|
public class Fx
|
||||||
|
{
|
||||||
|
public static void StartThread(ThreadStart threadStart)
|
||||||
|
{
|
||||||
|
new Thread(threadStart).Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SleepThread(int millisecondsTimeout)
|
||||||
|
{
|
||||||
|
Thread.Sleep(millisecondsTimeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
472
mqtt/M2Mqtt/Net/MqttNetworkChannel.cs
Normal file
472
mqtt/M2Mqtt/Net/MqttNetworkChannel.cs
Normal file
@ -0,0 +1,472 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if SSL
|
||||||
|
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
using Microsoft.SPOT.Net.Security;
|
||||||
|
#else
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Authentication;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System;
|
||||||
|
using System.Security.Authentication;
|
||||||
|
using System.Net.Security;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Channel to communicate over the network
|
||||||
|
/// </summary>
|
||||||
|
public class MqttNetworkChannel : IMqttNetworkChannel
|
||||||
|
{
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3 || COMPACT_FRAMEWORK)
|
||||||
|
private readonly RemoteCertificateValidationCallback userCertificateValidationCallback;
|
||||||
|
private readonly LocalCertificateSelectionCallback userCertificateSelectionCallback;
|
||||||
|
#endif
|
||||||
|
// remote host information
|
||||||
|
private string remoteHostName;
|
||||||
|
private IPAddress remoteIpAddress;
|
||||||
|
private int remotePort;
|
||||||
|
|
||||||
|
// socket for communication
|
||||||
|
private Socket socket;
|
||||||
|
// using SSL
|
||||||
|
private bool secure;
|
||||||
|
|
||||||
|
// CA certificate (on client)
|
||||||
|
private X509Certificate caCert;
|
||||||
|
// Server certificate (on broker)
|
||||||
|
private X509Certificate serverCert;
|
||||||
|
// client certificate (on client)
|
||||||
|
private X509Certificate clientCert;
|
||||||
|
|
||||||
|
// SSL/TLS protocol version
|
||||||
|
private MqttSslProtocols sslProtocol;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remote host name
|
||||||
|
/// </summary>
|
||||||
|
public string RemoteHostName { get { return this.remoteHostName; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remote IP address
|
||||||
|
/// </summary>
|
||||||
|
public IPAddress RemoteIpAddress { get { return this.remoteIpAddress; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remote port
|
||||||
|
/// </summary>
|
||||||
|
public int RemotePort { get { return this.remotePort; } }
|
||||||
|
|
||||||
|
#if SSL
|
||||||
|
// SSL stream
|
||||||
|
private SslStream sslStream;
|
||||||
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
private NetworkStream netStream;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data available on the channel
|
||||||
|
/// </summary>
|
||||||
|
public bool DataAvailable
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
#if SSL
|
||||||
|
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
if (secure)
|
||||||
|
return this.sslStream.DataAvailable;
|
||||||
|
else
|
||||||
|
return (this.socket.Available > 0);
|
||||||
|
#else
|
||||||
|
if (secure)
|
||||||
|
return this.netStream.DataAvailable;
|
||||||
|
else
|
||||||
|
return (this.socket.Available > 0);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
return (this.socket.Available > 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="socket">Socket opened with the client</param>
|
||||||
|
public MqttNetworkChannel(Socket socket)
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3 || COMPACT_FRAMEWORK)
|
||||||
|
: this(socket, false, null, MqttSslProtocols.None, null, null)
|
||||||
|
#else
|
||||||
|
: this(socket, false, null, MqttSslProtocols.None)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="socket">Socket opened with the client</param>
|
||||||
|
/// <param name="secure">Secure connection (SSL/TLS)</param>
|
||||||
|
/// <param name="serverCert">Server X509 certificate for secure connection</param>
|
||||||
|
/// <param name="sslProtocol">SSL/TLS protocol version</param>
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3 || COMPACT_FRAMEWORK)
|
||||||
|
/// <param name="userCertificateSelectionCallback">A RemoteCertificateValidationCallback delegate responsible for validating the certificate supplied by the remote party</param>
|
||||||
|
/// <param name="userCertificateValidationCallback">A LocalCertificateSelectionCallback delegate responsible for selecting the certificate used for authentication</param>
|
||||||
|
public MqttNetworkChannel(Socket socket, bool secure, X509Certificate serverCert, MqttSslProtocols sslProtocol,
|
||||||
|
RemoteCertificateValidationCallback userCertificateValidationCallback,
|
||||||
|
LocalCertificateSelectionCallback userCertificateSelectionCallback)
|
||||||
|
#else
|
||||||
|
public MqttNetworkChannel(Socket socket, bool secure, X509Certificate serverCert, MqttSslProtocols sslProtocol)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
this.socket = socket;
|
||||||
|
this.secure = secure;
|
||||||
|
this.serverCert = serverCert;
|
||||||
|
this.sslProtocol = sslProtocol;
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3 || COMPACT_FRAMEWORK)
|
||||||
|
this.userCertificateValidationCallback = userCertificateValidationCallback;
|
||||||
|
this.userCertificateSelectionCallback = userCertificateSelectionCallback;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="remoteHostName">Remote Host name</param>
|
||||||
|
/// <param name="remotePort">Remote port</param>
|
||||||
|
public MqttNetworkChannel(string remoteHostName, int remotePort)
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3 || COMPACT_FRAMEWORK)
|
||||||
|
: this(remoteHostName, remotePort, false, null, null, MqttSslProtocols.None, null, null)
|
||||||
|
#else
|
||||||
|
: this(remoteHostName, remotePort, false, null, null, MqttSslProtocols.None)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="remoteHostName">Remote Host name</param>
|
||||||
|
/// <param name="remotePort">Remote port</param>
|
||||||
|
/// <param name="secure">Using SSL</param>
|
||||||
|
/// <param name="caCert">CA certificate</param>
|
||||||
|
/// <param name="clientCert">Client certificate</param>
|
||||||
|
/// <param name="sslProtocol">SSL/TLS protocol version</param>
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3 || COMPACT_FRAMEWORK)
|
||||||
|
/// <param name="userCertificateSelectionCallback">A RemoteCertificateValidationCallback delegate responsible for validating the certificate supplied by the remote party</param>
|
||||||
|
/// <param name="userCertificateValidationCallback">A LocalCertificateSelectionCallback delegate responsible for selecting the certificate used for authentication</param>
|
||||||
|
public MqttNetworkChannel(string remoteHostName, int remotePort, bool secure, X509Certificate caCert, X509Certificate clientCert, MqttSslProtocols sslProtocol,
|
||||||
|
RemoteCertificateValidationCallback userCertificateValidationCallback,
|
||||||
|
LocalCertificateSelectionCallback userCertificateSelectionCallback)
|
||||||
|
#else
|
||||||
|
public MqttNetworkChannel(string remoteHostName, int remotePort, bool secure, X509Certificate caCert, X509Certificate clientCert, MqttSslProtocols sslProtocol)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
IPAddress remoteIpAddress = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// check if remoteHostName is a valid IP address and get it
|
||||||
|
remoteIpAddress = IPAddress.Parse(remoteHostName);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// in this case the parameter remoteHostName isn't a valid IP address
|
||||||
|
if (remoteIpAddress == null)
|
||||||
|
{
|
||||||
|
IPHostEntry hostEntry = Dns.GetHostEntry(remoteHostName);
|
||||||
|
if ((hostEntry != null) && (hostEntry.AddressList.Length > 0))
|
||||||
|
{
|
||||||
|
// check for the first address not null
|
||||||
|
// it seems that with .Net Micro Framework, the IPV6 addresses aren't supported and return "null"
|
||||||
|
int i = 0;
|
||||||
|
while (hostEntry.AddressList[i] == null) i++;
|
||||||
|
remoteIpAddress = hostEntry.AddressList[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("No address found for the remote host name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.remoteHostName = remoteHostName;
|
||||||
|
this.remoteIpAddress = remoteIpAddress;
|
||||||
|
this.remotePort = remotePort;
|
||||||
|
this.secure = secure;
|
||||||
|
this.caCert = caCert;
|
||||||
|
this.clientCert = clientCert;
|
||||||
|
this.sslProtocol = sslProtocol;
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3 || COMPACT_FRAMEWORK)
|
||||||
|
this.userCertificateValidationCallback = userCertificateValidationCallback;
|
||||||
|
this.userCertificateSelectionCallback = userCertificateSelectionCallback;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connect to remote server
|
||||||
|
/// </summary>
|
||||||
|
public void Connect()
|
||||||
|
{
|
||||||
|
this.socket = new Socket(IPAddressUtility.GetAddressFamily(this.remoteIpAddress), SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
// try connection to the broker
|
||||||
|
this.socket.Connect(new IPEndPoint(this.remoteIpAddress, this.remotePort));
|
||||||
|
|
||||||
|
#if SSL
|
||||||
|
// secure channel requested
|
||||||
|
if (secure)
|
||||||
|
{
|
||||||
|
// create SSL stream
|
||||||
|
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
this.sslStream = new SslStream(this.socket);
|
||||||
|
#else
|
||||||
|
this.netStream = new NetworkStream(this.socket);
|
||||||
|
this.sslStream = new SslStream(this.netStream, false, this.userCertificateValidationCallback, this.userCertificateSelectionCallback);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// server authentication (SSL/TLS handshake)
|
||||||
|
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
this.sslStream.AuthenticateAsClient(this.remoteHostName,
|
||||||
|
this.clientCert,
|
||||||
|
new X509Certificate[] { this.caCert },
|
||||||
|
SslVerification.CertificateRequired,
|
||||||
|
MqttSslUtility.ToSslPlatformEnum(this.sslProtocol));
|
||||||
|
#else
|
||||||
|
X509CertificateCollection clientCertificates = null;
|
||||||
|
// check if there is a client certificate to add to the collection, otherwise it's null (as empty)
|
||||||
|
if (this.clientCert != null)
|
||||||
|
clientCertificates = new X509CertificateCollection(new X509Certificate[] { this.clientCert });
|
||||||
|
|
||||||
|
this.sslStream.AuthenticateAsClient(this.remoteHostName,
|
||||||
|
clientCertificates,
|
||||||
|
MqttSslUtility.ToSslPlatformEnum(this.sslProtocol),
|
||||||
|
false);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Send data on the network channel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">Data buffer to send</param>
|
||||||
|
/// <returns>Number of byte sent</returns>
|
||||||
|
public int Send(byte[] buffer)
|
||||||
|
{
|
||||||
|
#if SSL
|
||||||
|
if (this.secure)
|
||||||
|
{
|
||||||
|
this.sslStream.Write(buffer, 0, buffer.Length);
|
||||||
|
this.sslStream.Flush();
|
||||||
|
return buffer.Length;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return this.socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
|
||||||
|
#else
|
||||||
|
return this.socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Receive data from the network
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">Data buffer for receiving data</param>
|
||||||
|
/// <returns>Number of bytes received</returns>
|
||||||
|
public int Receive(byte[] buffer)
|
||||||
|
{
|
||||||
|
#if SSL
|
||||||
|
if (this.secure)
|
||||||
|
{
|
||||||
|
// read all data needed (until fill buffer)
|
||||||
|
int idx = 0, read = 0;
|
||||||
|
while (idx < buffer.Length)
|
||||||
|
{
|
||||||
|
// fixed scenario with socket closed gracefully by peer/broker and
|
||||||
|
// Read return 0. Avoid infinite loop.
|
||||||
|
read = this.sslStream.Read(buffer, idx, buffer.Length - idx);
|
||||||
|
if (read == 0)
|
||||||
|
return 0;
|
||||||
|
idx += read;
|
||||||
|
}
|
||||||
|
return buffer.Length;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// read all data needed (until fill buffer)
|
||||||
|
int idx = 0, read = 0;
|
||||||
|
while (idx < buffer.Length)
|
||||||
|
{
|
||||||
|
// fixed scenario with socket closed gracefully by peer/broker and
|
||||||
|
// Read return 0. Avoid infinite loop.
|
||||||
|
read = this.socket.Receive(buffer, idx, buffer.Length - idx, SocketFlags.None);
|
||||||
|
if (read == 0)
|
||||||
|
return 0;
|
||||||
|
idx += read;
|
||||||
|
}
|
||||||
|
return buffer.Length;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// read all data needed (until fill buffer)
|
||||||
|
int idx = 0, read = 0;
|
||||||
|
while (idx < buffer.Length)
|
||||||
|
{
|
||||||
|
// fixed scenario with socket closed gracefully by peer/broker and
|
||||||
|
// Read return 0. Avoid infinite loop.
|
||||||
|
read = this.socket.Receive(buffer, idx, buffer.Length - idx, SocketFlags.None);
|
||||||
|
if (read == 0)
|
||||||
|
return 0;
|
||||||
|
idx += read;
|
||||||
|
}
|
||||||
|
return buffer.Length;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Receive data from the network channel with a specified timeout
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">Data buffer for receiving data</param>
|
||||||
|
/// <param name="timeout">Timeout on receiving (in milliseconds)</param>
|
||||||
|
/// <returns>Number of bytes received</returns>
|
||||||
|
public int Receive(byte[] buffer, int timeout)
|
||||||
|
{
|
||||||
|
// check data availability (timeout is in microseconds)
|
||||||
|
if (this.socket.Poll(timeout * 1000, SelectMode.SelectRead))
|
||||||
|
{
|
||||||
|
return this.Receive(buffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Close the network channel
|
||||||
|
/// </summary>
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
#if SSL
|
||||||
|
if (this.secure)
|
||||||
|
{
|
||||||
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
this.netStream.Close();
|
||||||
|
#endif
|
||||||
|
this.sslStream.Close();
|
||||||
|
}
|
||||||
|
this.socket.Close();
|
||||||
|
#else
|
||||||
|
this.socket.Close();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Accept connection from a remote client
|
||||||
|
/// </summary>
|
||||||
|
public void Accept()
|
||||||
|
{
|
||||||
|
#if SSL
|
||||||
|
// secure channel requested
|
||||||
|
if (secure)
|
||||||
|
{
|
||||||
|
#if !(MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
|
||||||
|
this.netStream = new NetworkStream(this.socket);
|
||||||
|
this.sslStream = new SslStream(this.netStream, false, this.userCertificateValidationCallback, this.userCertificateSelectionCallback);
|
||||||
|
|
||||||
|
this.sslStream.AuthenticateAsServer(this.serverCert, false, MqttSslUtility.ToSslPlatformEnum(this.sslProtocol), false);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// IPAddress Utility class
|
||||||
|
/// </summary>
|
||||||
|
public static class IPAddressUtility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Return AddressFamily for the IP address
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ipAddress">IP address to check</param>
|
||||||
|
/// <returns>Address family</returns>
|
||||||
|
public static AddressFamily GetAddressFamily(IPAddress ipAddress)
|
||||||
|
{
|
||||||
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
return ipAddress.AddressFamily;
|
||||||
|
#else
|
||||||
|
return (ipAddress.ToString().IndexOf(':') != -1) ?
|
||||||
|
AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// MQTT SSL utility class
|
||||||
|
/// </summary>
|
||||||
|
public static class MqttSslUtility
|
||||||
|
{
|
||||||
|
#if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3 && !COMPACT_FRAMEWORK)
|
||||||
|
public static SslProtocols ToSslPlatformEnum(MqttSslProtocols mqttSslProtocol)
|
||||||
|
{
|
||||||
|
switch (mqttSslProtocol)
|
||||||
|
{
|
||||||
|
case MqttSslProtocols.None:
|
||||||
|
return SslProtocols.None;
|
||||||
|
case MqttSslProtocols.SSLv3:
|
||||||
|
return SslProtocols.Ssl3;
|
||||||
|
case MqttSslProtocols.TLSv1_0:
|
||||||
|
return SslProtocols.Tls;
|
||||||
|
/*case MqttSslProtocols.TLSv1_1:
|
||||||
|
return SslProtocols.Tls11;
|
||||||
|
case MqttSslProtocols.TLSv1_2:
|
||||||
|
return SslProtocols.Tls12;*/
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("SSL/TLS protocol version not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)
|
||||||
|
public static SslProtocols ToSslPlatformEnum(MqttSslProtocols mqttSslProtocol)
|
||||||
|
{
|
||||||
|
switch (mqttSslProtocol)
|
||||||
|
{
|
||||||
|
case MqttSslProtocols.None:
|
||||||
|
return SslProtocols.None;
|
||||||
|
case MqttSslProtocols.SSLv3:
|
||||||
|
return SslProtocols.SSLv3;
|
||||||
|
case MqttSslProtocols.TLSv1_0:
|
||||||
|
return SslProtocols.TLSv1;
|
||||||
|
case MqttSslProtocols.TLSv1_1:
|
||||||
|
case MqttSslProtocols.TLSv1_2:
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("SSL/TLS protocol version not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
@ -1,46 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
This library is free software; you can redistribute it and/or
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
modify it under the terms of the GNU Lesser General Public
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
This library is distributed in the hope that it will be useful,
|
and the Eclipse Distribution License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
You should have received a copy of the GNU Lesser General Public
|
*/
|
||||||
License along with this library.
|
|
||||||
*/
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Reflection;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// General Information about an assembly is controlled through the following
|
// associated with an assembly.
|
||||||
// set of attributes. Change these attribute values to modify the information
|
[assembly: AssemblyTitle("M2Mqtt")]
|
||||||
// associated with an assembly.
|
[assembly: AssemblyDescription("MQTT Client Library for M2M communication")]
|
||||||
[assembly: AssemblyTitle("M2Mqtt")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyDescription("MQTT Client Library for M2M communication")]
|
[assembly: AssemblyCompany("Paolo Patierno")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyProduct("M2Mqtt")]
|
||||||
[assembly: AssemblyCompany("Paolo Patierno")]
|
[assembly: AssemblyCopyright("Copyright © Paolo Patierno 2014")]
|
||||||
[assembly: AssemblyProduct("M2Mqtt")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCopyright("Copyright © Paolo Patierno 2014")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
// Version information for an assembly consists of the following four values:
|
// Major Version
|
||||||
//
|
// Minor Version
|
||||||
// Major Version
|
// Build Number
|
||||||
// Minor Version
|
// Revision
|
||||||
// Build Number
|
//
|
||||||
// Revision
|
[assembly: AssemblyVersion("4.3.0.0")]
|
||||||
//
|
// to avoid compilation error (AssemblyFileVersionAttribute doesn't exist) under .Net CF 3.5
|
||||||
[assembly: AssemblyVersion("3.3.0.0")]
|
#if !WindowsCE
|
||||||
// to avoid compilation error (AssemblyFileVersionAttribute doesn't exist) under .Net CF 3.5
|
[assembly: AssemblyFileVersion("4.3.0.0")]
|
||||||
#if !WindowsCE
|
|
||||||
[assembly: AssemblyFileVersion("3.3.0.0")]
|
|
||||||
#endif
|
#endif
|
65
mqtt/M2Mqtt/Session/MqttBrokerSession.cs
Normal file
65
mqtt/M2Mqtt/Session/MqttBrokerSession.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if BROKER
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Managers;
|
||||||
|
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt.Session
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MQTT Broker Session
|
||||||
|
/// </summary>
|
||||||
|
public class MqttBrokerSession : MqttSession
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Client related to the subscription
|
||||||
|
/// </summary>
|
||||||
|
public MqttClient Client { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Subscriptions for the client session
|
||||||
|
/// </summary>
|
||||||
|
public List<MqttSubscription> Subscriptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Outgoing messages to publish
|
||||||
|
/// </summary>
|
||||||
|
public Queue<MqttMsgPublish> OutgoingMessages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public MqttBrokerSession()
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
this.Client = null;
|
||||||
|
this.Subscriptions = new List<MqttSubscription>();
|
||||||
|
this.OutgoingMessages = new Queue<MqttMsgPublish>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Clear()
|
||||||
|
{
|
||||||
|
base.Clear();
|
||||||
|
this.Client = null;
|
||||||
|
this.Subscriptions.Clear();
|
||||||
|
this.OutgoingMessages.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
33
mqtt/M2Mqtt/Session/MqttClientSession.cs
Normal file
33
mqtt/M2Mqtt/Session/MqttClientSession.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt.Session
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MQTT Client Session
|
||||||
|
/// </summary>
|
||||||
|
public class MqttClientSession : MqttSession
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientId">Client Id to create session</param>
|
||||||
|
public MqttClientSession(string clientId)
|
||||||
|
: base(clientId)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
mqtt/M2Mqtt/Session/MqttSession.cs
Normal file
63
mqtt/M2Mqtt/Session/MqttSession.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt.Session
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MQTT Session base class
|
||||||
|
/// </summary>
|
||||||
|
public abstract class MqttSession
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Client Id
|
||||||
|
/// </summary>
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Messages inflight during session
|
||||||
|
/// </summary>
|
||||||
|
public Hashtable InflightMessages { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public MqttSession()
|
||||||
|
: this(null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="clientId">Client Id to create session</param>
|
||||||
|
public MqttSession(string clientId)
|
||||||
|
{
|
||||||
|
this.ClientId = clientId;
|
||||||
|
this.InflightMessages = new Hashtable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean session
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Clear()
|
||||||
|
{
|
||||||
|
this.ClientId = null;
|
||||||
|
this.InflightMessages.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
M2Mqtt - MQTT Client Library for .Net
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
Copyright (c) 2014, Paolo Patierno, All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
All rights reserved. This program and the accompanying materials
|
||||||
modify it under the terms of the GNU Lesser General Public
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
License as published by the Free Software Foundation; either
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
The Eclipse Public License is available at
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
and the Eclipse Distribution License is available at
|
||||||
Lesser General Public License for more details.
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
Contributors:
|
||||||
License along with this library.
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace uPLibrary.Networking.M2Mqtt
|
namespace uPLibrary.Networking.M2Mqtt.Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extension class for a Queue
|
/// Extension class for a Queue
|
||||||
|
86
mqtt/M2Mqtt/Utility/Trace.cs
Normal file
86
mqtt/M2Mqtt/Utility/Trace.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt.Utility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tracing levels
|
||||||
|
/// </summary>
|
||||||
|
public enum TraceLevel
|
||||||
|
{
|
||||||
|
Error = 0x01,
|
||||||
|
Warning = 0x02,
|
||||||
|
Information = 0x04,
|
||||||
|
Verbose = 0x0F,
|
||||||
|
Frame = 0x10,
|
||||||
|
Queuing = 0x20
|
||||||
|
}
|
||||||
|
|
||||||
|
// delegate for writing trace
|
||||||
|
public delegate void WriteTrace(string format, params object[] args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tracing class
|
||||||
|
/// </summary>
|
||||||
|
public static class Trace
|
||||||
|
{
|
||||||
|
public static TraceLevel TraceLevel;
|
||||||
|
public static WriteTrace TraceListener;
|
||||||
|
|
||||||
|
[Conditional("DEBUG")]
|
||||||
|
public static void Debug(string format, params object[] args)
|
||||||
|
{
|
||||||
|
if (TraceListener != null)
|
||||||
|
{
|
||||||
|
TraceListener(format, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteLine(TraceLevel level, string format)
|
||||||
|
{
|
||||||
|
if (TraceListener != null && (level & TraceLevel) > 0)
|
||||||
|
{
|
||||||
|
TraceListener(format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteLine(TraceLevel level, string format, object arg1)
|
||||||
|
{
|
||||||
|
if (TraceListener != null && (level & TraceLevel) > 0)
|
||||||
|
{
|
||||||
|
TraceListener(format, arg1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteLine(TraceLevel level, string format, object arg1, object arg2)
|
||||||
|
{
|
||||||
|
if (TraceListener != null && (level & TraceLevel) > 0)
|
||||||
|
{
|
||||||
|
TraceListener(format, arg1, arg2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteLine(TraceLevel level, string format, object arg1, object arg2, object arg3)
|
||||||
|
{
|
||||||
|
if (TraceListener != null && (level & TraceLevel) > 0)
|
||||||
|
{
|
||||||
|
TraceListener(format, arg1, arg2, arg3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
mqtt/M2Mqtt/WinRT/Fx.cs
Normal file
36
mqtt/M2Mqtt/WinRT/Fx.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Support methods fos specific framework
|
||||||
|
/// </summary>
|
||||||
|
public class Fx
|
||||||
|
{
|
||||||
|
|
||||||
|
public delegate void ThreadStart();
|
||||||
|
public static void StartThread(ThreadStart threadStart)
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(o => ((ThreadStart)o)(), threadStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SleepThread(int millisecondsTimeout) { Task.Delay(millisecondsTimeout).RunSynchronously(); }
|
||||||
|
}
|
||||||
|
}
|
27
mqtt/M2Mqtt/WinRT/Hashtable.cs
Normal file
27
mqtt/M2Mqtt/WinRT/Hashtable.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper Hashtable class for generic Dictionary<TKey,TValue> (the only available in WinRT)
|
||||||
|
/// </summary>
|
||||||
|
public class Hashtable : Dictionary<object, object>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
179
mqtt/M2Mqtt/WinRT/MqttNetworkChannel.cs
Normal file
179
mqtt/M2Mqtt/WinRT/MqttNetworkChannel.cs
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Windows.Networking;
|
||||||
|
using Windows.Networking.Sockets;
|
||||||
|
using System.Runtime.InteropServices.WindowsRuntime;
|
||||||
|
using Windows.Storage.Streams;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
|
{
|
||||||
|
public class MqttNetworkChannel : IMqttNetworkChannel
|
||||||
|
{
|
||||||
|
// stream socket for communication
|
||||||
|
private StreamSocket socket;
|
||||||
|
|
||||||
|
// remote host information
|
||||||
|
private HostName remoteHostName;
|
||||||
|
private int remotePort;
|
||||||
|
|
||||||
|
// using SSL
|
||||||
|
private bool secure;
|
||||||
|
|
||||||
|
// SSL/TLS protocol version
|
||||||
|
private MqttSslProtocols sslProtocol;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="socket">Socket opened with the client</param>
|
||||||
|
public MqttNetworkChannel(StreamSocket socket)
|
||||||
|
{
|
||||||
|
this.socket = socket;
|
||||||
|
this.sslProtocol = MqttSslProtocols.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="remoteHostName">Remote Host name</param>
|
||||||
|
/// <param name="remotePort">Remote port</param>
|
||||||
|
/// <param name="secure">Using SSL</param>
|
||||||
|
/// <param name="sslProtocol">SSL/TLS protocol version</param>
|
||||||
|
public MqttNetworkChannel(string remoteHostName, int remotePort, bool secure, MqttSslProtocols sslProtocol)
|
||||||
|
{
|
||||||
|
this.remoteHostName = new HostName(remoteHostName);
|
||||||
|
this.remotePort = remotePort;
|
||||||
|
this.secure = secure;
|
||||||
|
this.sslProtocol = sslProtocol;
|
||||||
|
|
||||||
|
if (secure && (sslProtocol == MqttSslProtocols.None))
|
||||||
|
throw new ArgumentException("For secure connection, an SSL/TLS protocol version is needed");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DataAvailable
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Receive(byte[] buffer)
|
||||||
|
{
|
||||||
|
IBuffer result;
|
||||||
|
|
||||||
|
// read all data needed (until fill buffer)
|
||||||
|
int idx = 0;
|
||||||
|
while (idx < buffer.Length)
|
||||||
|
{
|
||||||
|
// fixed scenario with socket closed gracefully by peer/broker and
|
||||||
|
// Read return 0. Avoid infinite loop.
|
||||||
|
|
||||||
|
// read is executed synchronously
|
||||||
|
result = this.socket.InputStream.ReadAsync(buffer.AsBuffer(), (uint)buffer.Length, InputStreamOptions.None).AsTask().Result;
|
||||||
|
if (result.Length == 0)
|
||||||
|
return 0;
|
||||||
|
idx += (int)result.Length;
|
||||||
|
}
|
||||||
|
return buffer.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Receive(byte[] buffer, int timeout)
|
||||||
|
{
|
||||||
|
CancellationTokenSource cts = new CancellationTokenSource(timeout);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IBuffer result;
|
||||||
|
|
||||||
|
// read all data needed (until fill buffer)
|
||||||
|
int idx = 0;
|
||||||
|
while (idx < buffer.Length)
|
||||||
|
{
|
||||||
|
// fixed scenario with socket closed gracefully by peer/broker and
|
||||||
|
// Read return 0. Avoid infinite loop.
|
||||||
|
|
||||||
|
// read is executed synchronously
|
||||||
|
result = this.socket.InputStream.ReadAsync(buffer.AsBuffer(), (uint)buffer.Length, InputStreamOptions.None).AsTask(cts.Token).Result;
|
||||||
|
if (result.Length == 0)
|
||||||
|
return 0;
|
||||||
|
idx += (int)result.Length;
|
||||||
|
}
|
||||||
|
return buffer.Length;
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Send(byte[] buffer)
|
||||||
|
{
|
||||||
|
// send is executed synchronously
|
||||||
|
return (int)this.socket.OutputStream.WriteAsync(buffer.AsBuffer()).AsTask().Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
this.socket.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Connect()
|
||||||
|
{
|
||||||
|
this.socket = new StreamSocket();
|
||||||
|
|
||||||
|
// connection is executed synchronously
|
||||||
|
this.socket.ConnectAsync(this.remoteHostName,
|
||||||
|
this.remotePort.ToString(),
|
||||||
|
MqttSslUtility.ToSslPlatformEnum(this.sslProtocol)).AsTask().Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Accept()
|
||||||
|
{
|
||||||
|
// TODO : SSL support with StreamSocket / StreamSocketListener seems to be NOT supported
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// MQTT SSL utility class
|
||||||
|
/// </summary>
|
||||||
|
public static class MqttSslUtility
|
||||||
|
{
|
||||||
|
public static SocketProtectionLevel ToSslPlatformEnum(MqttSslProtocols mqttSslProtocol)
|
||||||
|
{
|
||||||
|
switch (mqttSslProtocol)
|
||||||
|
{
|
||||||
|
case MqttSslProtocols.None:
|
||||||
|
return SocketProtectionLevel.PlainSocket;
|
||||||
|
case MqttSslProtocols.SSLv3:
|
||||||
|
return SocketProtectionLevel.SslAllowNullEncryption;
|
||||||
|
case MqttSslProtocols.TLSv1_0:
|
||||||
|
return SocketProtectionLevel.Tls10;
|
||||||
|
case MqttSslProtocols.TLSv1_1:
|
||||||
|
return SocketProtectionLevel.Tls11;
|
||||||
|
case MqttSslProtocols.TLSv1_2:
|
||||||
|
return SocketProtectionLevel.Tls12;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("SSL/TLS protocol version not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
mqtt/M2Mqtt/WinRT/Queue.cs
Normal file
27
mqtt/M2Mqtt/WinRT/Queue.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2013, 2014 Paolo Patierno
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Paolo Patierno - initial API and implementation and/or initial documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace uPLibrary.Networking.M2Mqtt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper Queue class for generic Queue<T> (the only available in WinRT)
|
||||||
|
/// </summary>
|
||||||
|
public class Queue : Queue<object>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
@ -1,75 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<AssemblyName>M2Mqtt</AssemblyName>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<RootNamespace>uPLibrary.Networking.M2Mqtt</RootNamespace>
|
|
||||||
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
|
||||||
<ProductVersion>9.0.21022</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectGuid>{F733523A-F14E-4F5A-9E7C-085CA80F52B1}</ProjectGuid>
|
|
||||||
<TargetFrameworkVersion>v4.2</TargetFrameworkVersion>
|
|
||||||
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\NetMf42\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE,MF_FRAMEWORK_VERSION_V4_2,SSL</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\NetMf42\</OutputPath>
|
|
||||||
<DefineConstants>TRACE,MF_FRAMEWORK_VERSION_V4_2,SSL</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Exceptions\MqttClientException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttCommunicationException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttConnectionException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttTimeoutException.cs" />
|
|
||||||
<Compile Include="IMqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgBase.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnack.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnectEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgContext.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgDisconnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingReq.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingResp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubcomp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublish.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrec.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="MqttClient.cs" />
|
|
||||||
<Compile Include="MqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="MqttSettings.cs" />
|
|
||||||
<Compile Include="Utility\QueueExtension.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.SPOT.Native">
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.SPOT.Net.Security" />
|
|
||||||
<Reference Include="Microsoft.SPOT.Time" />
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Net.Security" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
@ -1,75 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<AssemblyName>M2Mqtt</AssemblyName>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<RootNamespace>uPLibrary.Networking.M2Mqtt</RootNamespace>
|
|
||||||
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
|
||||||
<ProductVersion>9.0.21022</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectGuid>{6A6D540B-8554-4FFD-8884-8BEFCCD9AD41}</ProjectGuid>
|
|
||||||
<TargetFrameworkVersion>v4.3</TargetFrameworkVersion>
|
|
||||||
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\NetMf43\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE,MF_FRAMEWORK_VERSION_V4_3,SSL</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\NetMf43\</OutputPath>
|
|
||||||
<DefineConstants>TRACE,MF_FRAMEWORK_VERSION_V4_3,SSL</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Exceptions\MqttClientException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttCommunicationException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttConnectionException.cs" />
|
|
||||||
<Compile Include="Exceptions\MqttTimeoutException.cs" />
|
|
||||||
<Compile Include="IMqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgBase.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnack.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgConnectEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgContext.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgDisconnect.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingReq.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPingResp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubcomp.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublish.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPublishEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrec.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgPubrel.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgSubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsuback.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribe.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribedEventArgs.cs" />
|
|
||||||
<Compile Include="Messages\MqttMsgUnsubscribeEventArgs.cs" />
|
|
||||||
<Compile Include="MqttClient.cs" />
|
|
||||||
<Compile Include="MqttNetworkChannel.cs" />
|
|
||||||
<Compile Include="MqttSettings.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="Utility\QueueExtension.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.SPOT.Native">
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.SPOT.Net.Security" />
|
|
||||||
<Reference Include="Microsoft.SPOT.Time" />
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Net.Security" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
Loading…
Reference in New Issue
Block a user