初始化

This commit is contained in:
2025-12-11 14:04:39 +08:00
commit 1f65bbf628
2676 changed files with 838983 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MQTTnet" Version="5.0.1.1416" />
<PackageReference Include="MQTTnet.Server" Version="5.0.1.1416" />
</ItemGroup>
</Project>

60
IotMqttServer/Program.cs Normal file
View File

@@ -0,0 +1,60 @@
using MQTTnet.Protocol;
using MQTTnet.Server;
namespace IotMqttServer
{
internal class Program
{
static async Task Main(string[] args)
{
var mqttServerFactory = new MqttServerFactory();
var mqttServerOptions = new MqttServerOptionsBuilder().WithDefaultEndpoint().Build();
using (var mqttServer = mqttServerFactory.CreateMqttServer(mqttServerOptions))
{
// Setup connection validation before starting the server so that there is
// no change to connect without valid credentials.
mqttServer.ValidatingConnectionAsync += e =>
{
//if (e.ClientId != "ValidClientId")
//{
// e.ReasonCode = MqttConnectReasonCode.ClientIdentifierNotValid;
//}
//if (e.UserName != "ValidUser")
//{
// e.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
//}
//if (e.Password != "SecretPassword")
//{
// e.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
//}
return Task.CompletedTask;
};
mqttServer.ClientDisconnectedAsync += MqttServer_ClientDisconnectedAsync;
mqttServer.ClientConnectedAsync += MqttServer_ClientConnectedAsync;
await mqttServer.StartAsync();
Console.WriteLine("Press Enter to exit.");
Console.ReadLine();
await mqttServer.StopAsync();
}
Console.WriteLine("Hello, World!");
}
private static Task MqttServer_ClientDisconnectedAsync(ClientDisconnectedEventArgs arg)
{
throw new NotImplementedException();
}
private static Task MqttServer_ClientConnectedAsync(ClientConnectedEventArgs arg)
{
throw new NotImplementedException();
}
}
}