初始化
This commit is contained in:
77
iotsystem/Program.cs
Normal file
77
iotsystem/Program.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace iotsystem
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
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.ReadLine();
|
||||
await mqttServer.StopAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Task MqttServer_ClientConnectedAsync(ClientConnectedEventArgs arg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static Task MqttServer_ClientDisconnectedAsync(ClientDisconnectedEventArgs arg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user