我想在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域设置是有效的。