• 大小: 5.91M
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: 客户端  服务  源码  NET  MQTT  

资源简介

本示例主要实现了以下三点:

1. 自建了mqtt 服务端(broker),并可以接收客户端发来的各种topic

2. 实现了客户端发布订阅mqtt消息

3. 实现了 服务端直接向外广播topic,客户端只需要 订阅该topic即可


调试步骤如下:

1. 运行>>cmd>>  cd 至 MQTTnet.TestApp.AspNetCore2 目录,并执行 dotnet run

2. 浏览器输入 http://localhost:5000 即可看到如下截图,浏览器输入 http://localhost:5000/publish 即可通过服务端发布topic

资源截图

代码片段和文件信息

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using MQTTnet.AspNetCore;

namespace MQTTnet.TestApp.AspNetCore2
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        private static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseKestrel(o => {
                    o.ListenAnyIP(1883 l => l.UseMqtt());
                    o.ListenAnyIP(5000); // default http pipeline
                })
                .UseStartup()
                .Build();
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-01 14:23  .vs\
     目录           0  2018-10-01 15:24  .vs\MQTTnet.TestApp.AspNetCore2\
     目录           0  2018-10-01 15:24  .vs\MQTTnet.TestApp.AspNetCore2\DesignTimeBuild\
     文件     1206588  2018-10-01 15:24  .vs\MQTTnet.TestApp.AspNetCore2\DesignTimeBuild\.dtbcache
     目录           0  2018-10-01 14:22  .vs\MQTTnet.TestApp.AspNetCore2\v15\
     文件       50688  2018-10-01 15:24  .vs\MQTTnet.TestApp.AspNetCore2\v15\.suo
     目录           0  2018-10-01 14:20  .vs\MQTTnet.TestApp.AspNetCore2\v15\Server\
     目录           0  2018-10-01 14:20  .vs\MQTTnet.TestApp.AspNetCore2\v15\Server\sqlite3\
     文件           0  2018-10-01 14:20  .vs\MQTTnet.TestApp.AspNetCore2\v15\Server\sqlite3\db.lock
     文件     1945600  2018-10-01 15:20  .vs\MQTTnet.TestApp.AspNetCore2\v15\Server\sqlite3\storage.ide
     文件       32768  2018-10-01 14:20  .vs\MQTTnet.TestApp.AspNetCore2\v15\Server\sqlite3\storage.ide-shm
     文件     4140632  2018-10-01 15:24  .vs\MQTTnet.TestApp.AspNetCore2\v15\Server\sqlite3\storage.ide-wal
     目录           0  2018-10-01 14:23  .vs\config\
     文件       80097  2018-10-01 14:23  .vs\config\applicationhost.config
     文件         611  2018-10-01 14:22  MQTTnet.TestApp.AspNetCore2.csproj
     文件         409  2018-10-01 14:24  MQTTnet.TestApp.AspNetCore2.csproj.user
     文件        1152  2018-10-01 14:22  MQTTnet.TestApp.AspNetCore2.sln
     文件         640  2018-07-08 20:10  Program.cs
     目录           0  2018-10-01 14:19  Properties\
     文件         665  2018-09-30 22:24  Properties\launchSettings.json
     文件        3905  2018-10-01 15:21  Startup.cs
     目录           0  2018-10-01 14:19  bin\
     目录           0  2018-10-01 14:19  bin\Debug\
     目录           0  2018-10-01 14:23  bin\Debug\netcoreapp2.1\
     文件      241734  2018-10-01 14:24  bin\Debug\netcoreapp2.1\MQTTnet.TestApp.AspNetCore2.deps.json
     文件       13312  2018-10-01 15:14  bin\Debug\netcoreapp2.1\MQTTnet.TestApp.AspNetCore2.dll
     文件        1872  2018-10-01 15:14  bin\Debug\netcoreapp2.1\MQTTnet.TestApp.AspNetCore2.pdb
     文件         252  2018-10-01 14:23  bin\Debug\netcoreapp2.1\MQTTnet.TestApp.AspNetCore2.runtimeconfig.dev.json
     文件         224  2018-10-01 14:23  bin\Debug\netcoreapp2.1\MQTTnet.TestApp.AspNetCore2.runtimeconfig.json
     目录           0  2018-10-01 14:19  node_modules\
     目录           0  2018-10-01 14:19  node_modules\.bin\
............此处省略710个文件信息

评论

共有 条评论