我在使用带有 C++/WinRT 的 DN-SD 的 Windows.Devices.Enumeration 及其 DeviceWatcher 时遇到问题。我的机器中有 2 个网卡,并且只能找到通过第一张网卡连接的机器上的那些服务。
这发生在我自己的测试程序中以及当我在 Microsoft 的“Windows 通用示例”中扩展 DeviceEnumeration 示例程序以包含 DNS-SD 时,例如添加到 Samples/DeviceEnumerationAndPairing/cpp/DisplayHelpers.h 中的 DeviceSelectorChoices
static property DeviceSelectorInfo^ Dnssd
{
DeviceSelectorInfo^ get();
}
并到 Samples/DeviceEnumerationAndPairing/cpp/DisplayHelpers.cpp 插入
DeviceSelectorInfo^ DeviceSelectorChoices::Dnssd::get()
{
return ref new DeviceSelectorInfo("DNS-SD",
DeviceClass::All,
"System.Devices.AepService.ProtocolId:=\"{4526e8c1-8aac-4153-9b16-55e86ada0e54}\" "
"AND System.Devices.Dnssd.ServiceName:=\"_myservice._tcp\"",
DeviceInformationKind::AssociationEndpointService);
}
到 Samples/DeviceEnumerationAndPairing/cpp/DisplayHelpers.cpp 并更新方法:
IVectorView<DeviceSelectorInfo^>^ DeviceSelectorChoices::DeviceWatcherSelectors::get()
{
Vector<DeviceSelectorInfo^>^ selectors = ref new Vector<DeviceSelectorInfo^>(begin(CommonDeviceSelectors), end(CommonDeviceSelectors));
selectors->Append(Dnssd);
...
然后编译并运行并从设备观察程序中选择 DNS-SD - 它只会在与第一个网络接口的子网连接的机器上找到服务,即使它在第二个网络接口的子网上有连接也是如此。但它没有列出仅在第二个网络上的机器上运行的任何服务。
使用 dns-sd 命令行工具查找两个网络上的所有广告服务:
dns-sd -B _myservice._tcp
我在 AQSFilter 上尝试了许多变体,认为它可能不会默认使用两个网络接口 - 例如使用 System.Devices.Dnssd.NetworkAdapterId - 但没有乐趣。
我想它也有可能在 Windows 中低于设备枚举 API ..?