我正在尝试在key
应用中使用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
回调。
我想念什么吗?
答案 0 :(得分:0)
您需要添加所需的内容。这是我的工作代码:
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域设置有效。