mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 03:24:33 +08:00
Add nuget support
This commit is contained in:
@@ -66,7 +66,7 @@ namespace MQTTnet.Core.Client
|
||||
_packetDispatcher.Reset();
|
||||
IsConnected = true;
|
||||
|
||||
Task.Run(async () => await ReceivePackets(_cancellationTokenSource.Token), _cancellationTokenSource.Token).Forget();
|
||||
Task.Run(() => ReceivePackets(_cancellationTokenSource.Token), _cancellationTokenSource.Token).Forget();
|
||||
|
||||
var response = await SendAndReceiveAsync<MqttConnAckPacket>(connectPacket);
|
||||
if (response.ConnectReturnCode != MqttConnectReturnCode.ConnectionAccepted)
|
||||
@@ -76,7 +76,7 @@ namespace MQTTnet.Core.Client
|
||||
|
||||
if (_options.KeepAlivePeriod != TimeSpan.Zero)
|
||||
{
|
||||
Task.Run(async () => await SendKeepAliveMessagesAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token).Forget();
|
||||
Task.Run(() => SendKeepAliveMessagesAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token).Forget();
|
||||
}
|
||||
|
||||
Connected?.Invoke(this, EventArgs.Empty);
|
||||
@@ -114,13 +114,7 @@ namespace MQTTnet.Core.Client
|
||||
throw new MqttProtocolViolationException("The return codes are not matching the topic filters [MQTT-3.9.3-1].");
|
||||
}
|
||||
|
||||
var result = new List<MqttSubscribeResult>();
|
||||
for (var i = 0; i < topicFilters.Count; i++)
|
||||
{
|
||||
result.Add(new MqttSubscribeResult(topicFilters[i], response.SubscribeReturnCodes[i]));
|
||||
}
|
||||
|
||||
return result;
|
||||
return topicFilters.Select((t, i) => new MqttSubscribeResult(t, response.SubscribeReturnCodes[i])).ToList();
|
||||
}
|
||||
|
||||
public async Task Unsubscribe(params string[] topicFilters)
|
||||
|
||||
@@ -1,107 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.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')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{99C884F3-B4B9-417D-AA92-DC7DD1C4CFEE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MQTTnet.Core</RootNamespace>
|
||||
<TargetFramework>netstandard1.1</TargetFramework>
|
||||
<AssemblyName>MQTTnet.Core</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<RootNamespace>MQTTnet.Core</RootNamespace>
|
||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||
<Description>MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker).</Description>
|
||||
<Product>MQTTnet</Product>
|
||||
<Company>Christian Kratky</Company>
|
||||
<Authors>Christian Kratky</Authors>
|
||||
<Version>2.1.0.11</Version>
|
||||
<PackageId>MQTTnet.Core</PackageId>
|
||||
<Copyright>Copyright © Christian Kratky 2016-2017</Copyright>
|
||||
<PackageProjectUrl>https://github.com/chkr1011/MQTTnet</PackageProjectUrl>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png</PackageIconUrl>
|
||||
<RepositoryUrl>https://github.com/chkr1011/MQTTnet</RepositoryUrl>
|
||||
<PackageTags>MQTT MQTTClient MQTTServer MQTTBroker Broker</PackageTags>
|
||||
<FileVersion>2.1.0.11</FileVersion>
|
||||
<AssemblyVersion>2.1.0.11</AssemblyVersion>
|
||||
<PackageLicenseUrl>https://github.com/chkr1011/MQTTnet/blob/master/LICENSE</PackageLicenseUrl>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- A reference to the entire .NET Framework is automatically included -->
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Adapter\IMqttCommunicationAdapter.cs" />
|
||||
<Compile Include="Adapter\IMqttServerAdapter.cs" />
|
||||
<Compile Include="Adapter\MqttClientConnectedEventArgs.cs" />
|
||||
<Compile Include="Adapter\MqttConnectingFailedException.cs" />
|
||||
<Compile Include="Adapter\MqttChannelCommunicationAdapter.cs" />
|
||||
<Compile Include="Channel\IMqttCommunicationChannel.cs" />
|
||||
<Compile Include="Client\MqttPacketDispatcher.cs" />
|
||||
<Compile Include="Client\MqttSubscribeResult.cs" />
|
||||
<Compile Include="Client\MqttPacketAwaiter.cs" />
|
||||
<Compile Include="Diagnostics\MqttTrace.cs" />
|
||||
<Compile Include="Diagnostics\MqttTraceLevel.cs" />
|
||||
<Compile Include="Diagnostics\MqttTraceMessagePublishedEventArgs.cs" />
|
||||
<Compile Include="Exceptions\MqttCommunicationException.cs" />
|
||||
<Compile Include="Exceptions\MqttCommunicationTimedOutException.cs" />
|
||||
<Compile Include="Exceptions\MqttProtocolViolationException.cs" />
|
||||
<Compile Include="Internal\MqttApplicationMessageExtensions.cs" />
|
||||
<Compile Include="MqttApplicationMessageReceivedEventArgs.cs" />
|
||||
<Compile Include="Packets\IPacketWithPacketIdentifier.cs" />
|
||||
<Compile Include="Packets\MqttConnAckPacket.cs" />
|
||||
<Compile Include="Packets\MqttBasePacket.cs" />
|
||||
<Compile Include="Packets\MqttConnectPacket.cs" />
|
||||
<Compile Include="Packets\MqttDisconnectPacket.cs" />
|
||||
<Compile Include="MqttApplicationMessage.cs" />
|
||||
<Compile Include="Client\MqttClient.cs" />
|
||||
<Compile Include="Client\MqttClientOptions.cs" />
|
||||
<Compile Include="Packets\MqttPingReqPacket.cs" />
|
||||
<Compile Include="Packets\MqttPubCompPacket.cs" />
|
||||
<Compile Include="Packets\MqttBasePublishPacket.cs" />
|
||||
<Compile Include="Packets\MqttUnsubAckPacket.cs" />
|
||||
<Compile Include="Packets\MqttSubAckPacket.cs" />
|
||||
<Compile Include="Packets\MqttPubRelPacket.cs" />
|
||||
<Compile Include="Packets\MqttPingRespPacket.cs" />
|
||||
<Compile Include="Packets\MqttPubAckPacket.cs" />
|
||||
<Compile Include="Packets\MqttPublishPacket.cs" />
|
||||
<Compile Include="Packets\MqttPubRecPacket.cs" />
|
||||
<Compile Include="Packets\MqttUnsubscribe.cs" />
|
||||
<Compile Include="Packets\MqttSubscribePacket.cs" />
|
||||
<Compile Include="Packets\TopicFilter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Protocol\MqttConnectReturnCode.cs" />
|
||||
<Compile Include="Protocol\MqttControlPacketType.cs" />
|
||||
<Compile Include="Protocol\MqttQualityOfServiceLevel.cs" />
|
||||
<Compile Include="Protocol\MqttSubscribeReturnCode.cs" />
|
||||
<Compile Include="Serializer\ByteReader.cs" />
|
||||
<Compile Include="Serializer\ByteWriter.cs" />
|
||||
<Compile Include="Serializer\DefaultMqttV311PacketSerializer.cs" />
|
||||
<Compile Include="Serializer\IMqttPacketSerializer.cs" />
|
||||
<Compile Include="Serializer\MqttPacketReader.cs" />
|
||||
<Compile Include="Serializer\MqttPacketWriter.cs" />
|
||||
<Compile Include="Server\MqttClientSession.cs" />
|
||||
<Compile Include="Server\MqttClientSessionManager.cs" />
|
||||
<Compile Include="Server\MqttOutgoingPublicationsManager.cs" />
|
||||
<Compile Include="Server\MqttServer.cs" />
|
||||
<Compile Include="Server\MqttServerOptions.cs" />
|
||||
<Compile Include="Server\MqttClientPublishPacketContext.cs" />
|
||||
<Compile Include="Server\MqttTopicFilterComparer.cs" />
|
||||
<Compile Include="Server\MqttClientSubscriptionsManager.cs" />
|
||||
<Compile Include="Internal\TaskExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.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>
|
||||
-->
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Any CPU|AnyCPU'" />
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Any CPU|x64'" />
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" />
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" />
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Any CPU|x86'" />
|
||||
|
||||
</Project>
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("MQTTnet")]
|
||||
[assembly: AssemblyDescription("The core library of MQTTnet")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Christian Kratky")]
|
||||
[assembly: AssemblyProduct("MQTTnet")]
|
||||
[assembly: AssemblyCopyright("Copyright © Christian Kratky 2016-2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("0e10d0ea-8e4b-4903-ab9e-93a187d07922")]
|
||||
[assembly: AssemblyVersion("2.1.0.4")]
|
||||
[assembly: AssemblyFileVersion("2.1.0.4")]
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -216,7 +215,7 @@ namespace MQTTnet.Core.Serializer
|
||||
|
||||
default:
|
||||
{
|
||||
throw new ProtocolViolationException();
|
||||
throw new MqttProtocolViolationException("Packet type not supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -292,7 +291,7 @@ namespace MQTTnet.Core.Serializer
|
||||
|
||||
if (Encoding.UTF8.GetString(protocolName, 0, protocolName.Length) != "MQTT")
|
||||
{
|
||||
throw new ProtocolViolationException("Protocol name is not 'MQTT'.");
|
||||
throw new MqttProtocolViolationException("Protocol name is not 'MQTT'.");
|
||||
}
|
||||
|
||||
var protocolLevel = await reader.ReadRemainingDataByteAsync();
|
||||
@@ -366,12 +365,12 @@ namespace MQTTnet.Core.Serializer
|
||||
{
|
||||
if (string.IsNullOrEmpty(packet.ClientId) && !packet.CleanSession)
|
||||
{
|
||||
throw new ProtocolViolationException("CleanSession must be set if ClientId is empty [MQTT-3.1.3-7].");
|
||||
throw new MqttProtocolViolationException("CleanSession must be set if ClientId is empty [MQTT-3.1.3-7].");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(packet.ClientId) && !Regex.IsMatch(packet.ClientId, "^[a-zA-Z0-9]*$"))
|
||||
{
|
||||
throw new ProtocolViolationException("ClientId contains invalid characters [MQTT-3.1.3-5].");
|
||||
throw new MqttProtocolViolationException("ClientId contains invalid characters [MQTT-3.1.3-5].");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +378,7 @@ namespace MQTTnet.Core.Serializer
|
||||
{
|
||||
if (packet.QualityOfServiceLevel == 0 && packet.Dup)
|
||||
{
|
||||
throw new ProtocolViolationException("Dup flag must be false for QoS 0 packets [MQTT-3.3.1-2].");
|
||||
throw new MqttProtocolViolationException("Dup flag must be false for QoS 0 packets [MQTT-3.3.1-2].");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,19 +23,20 @@ namespace MQTTnet.Core.Server
|
||||
_clientSessionManager = new MqttClientSessionManager(options);
|
||||
}
|
||||
|
||||
public event EventHandler<MqttClientConnectedEventArgs> ClientConnected;
|
||||
|
||||
public void InjectClient(string identifier, IMqttCommunicationAdapter adapter)
|
||||
{
|
||||
if (adapter == null) throw new ArgumentNullException(nameof(adapter));
|
||||
|
||||
if (_cancellationTokenSource == null) throw new InvalidOperationException("The MQTT server is not started.");
|
||||
|
||||
OnClientConnected(this, new MqttClientConnectedEventArgs(identifier, adapter));
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (_cancellationTokenSource != null)
|
||||
{
|
||||
throw new InvalidOperationException("The server is already started.");
|
||||
}
|
||||
if (_cancellationTokenSource != null) throw new InvalidOperationException("The MQTT server is already started.");
|
||||
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
@@ -61,6 +62,8 @@ namespace MQTTnet.Core.Server
|
||||
private void OnClientConnected(object sender, MqttClientConnectedEventArgs eventArgs)
|
||||
{
|
||||
MqttTrace.Information(nameof(MqttServer), $"Client '{eventArgs.Identifier}': Connected.");
|
||||
ClientConnected?.Invoke(this, eventArgs);
|
||||
|
||||
Task.Run(async () => await _clientSessionManager.RunClientSessionAsync(eventArgs), _cancellationTokenSource.Token).Forget();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user