uwp - 如何在 Windows 10 中枚举 mDNS 服务?
问题描述
我正在尝试DeviceInformation.CreateWatcher
在UWP
应用程序中使用来枚举mDNS
服务:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (_dnsWatcher == null)
{
_dnsWatcher = DeviceInformation.CreateWatcher("(System.Devices.Aep.ProtocolId:=\"{4526e8c1-8aac-4153-9b16-55e86ada0e54}\")");
_dnsWatcher.Added += DnsWatcher_Added;
_dnsWatcher.EnumerationCompleted += DnsWatcher_EnumerationCompleted;
_dnsWatcher.Removed += DnsWatcher_Removed;
_dnsWatcher.Stopped += DnsWatcher_Stopped;
_dnsWatcher.Updated += DnsWatcher_Updated;
_dnsWatcher.Start();
}
}
Wireshark
显示没有mDNS
广播,只有EnumerationCompleted
回调发生。
我错过了什么吗?
解决方案
您需要添加您正在观看的内容。这是我的工作代码:
var proto = "_gopher._tcp"; // e.g. _http._tcp
var queryString = $"System.Devices.AepService.ProtocolId:={{{DnsSdProtocol}}} AND System.Devices.Dnssd.ServiceName:=\"{proto}\" AND System.Devices.Dnssd.Domain:=\"local\"";
var askFor = new String[] { "System.Devices.Dnssd.HostName",
"System.Devices.Dnssd.ServiceName",
"System.Devices.Dnssd.InstanceName",
"System.Devices.IpAddress",
"System.Devices.Dnssd.PortNumber",
"System.Devices.Dnssd.TextAttributes",
};
dw = DeviceInformation.CreateWatcher(queryString, askFor, DeviceInformationKind.AssociationEndpointService);
请注意,我的查询字符串包含一个用于搜索 (_gopher._tcp) 的协议和一个 dns 域。警告:我是 DNS-SD 的新手,我不知道哪些 dns 域设置有效。
推荐阅读
- tensorflow - 用于 MNIST 的 CNN,具有高效的滑动窗口,可实时检测
- gatsby - Netlify 部署:带模糊的图像
- clojure - 使用 instaparse 动态构建 clara 规则时遇到问题
- node.js - 在超级账本结构中动态执行事务时出错
- php - 正则表达式模式结束子组
- python - 如何正确创建日期范围并重新排列(使用交叉表/数据透视表)表?
- java - 如何通过freemarker中的键值访问json值?
- angular - 如何从以下http请求中获取数据
- c# - 单元测试 Catch 块
- javascript - 用静态 getDerivedStateFromProps 替换 componentWillReceiveProps 的问题