0

I am looking to use this api (DnssdServiceInstance to broadcast a mDNS service entry. I have the extremely simple test app in c# (blank console app created in Visual Studio):

using Windows.Networking.ServiceDiscovery.Dnssd;

string InstanceName = "test1";
string SERVICE_TYPE = "_http";
string NETWORK_PROTOCOL = "_tcp";
string DOMAIN = "local";

//string fullServiceName = $"{InstanceName}.{SERVICE_TYPE}.{NETWORK_PROTOCOL}.{DOMAIN}";
string fullServiceName = $"{InstanceName}.{DOMAIN}";
DnssdServiceInstance service = new DnssdServiceInstance(fullServiceName, new("127.0.0.1"), 2222);

Console.ReadLine();

I then try to resolve this address from the same machine using Resolve-DnsName test1.local in powershell, but have never gotten any result except DNS name does not exist. I can resolve an mDNS service broadcast by avahi on an Ubuntu WSL instance using the same command, but never anything for the windows service.

Has anyone been able to get the Windows mDNS broadcast api to work?

I have tried defining the service name as both test1.local and test1._http._tcp.local. I have also tried running this code inside of a UWP app with Internet (Client and Server) capabilities requested. No combination I have tried so far has been resolvable.

I would prefer not to use an external dependency if at all possible.

2 Answers 2

0

Try getting rid of the .local in your query:

Resolve-DnsName test1
Sign up to request clarification or add additional context in comments.

1 Comment

This gives the same output as with the .local
0
using Windows.Networking.Connectivity;
using Windows.Networking;
using Windows.Networking.ServiceDiscovery.Dnssd;
using Windows.Networking.Sockets;

string InstanceName = "test1";
string SERVICE_TYPE = "_http";
string NETWORK_PROTOCOL = "_tcp";
string DOMAIN = "local";

string fullServiceName = $"{InstanceName}.{SERVICE_TYPE}.{NETWORK_PROTOCOL}.{DOMAIN}";
HostName hostName = NetworkInformation
    .GetHostNames()
    .First(x => x.Type == HostNameType.DomainName && x.RawName.Contains(".local"));
Console.WriteLine(fullServiceName);
Console.WriteLine(hostName);

DnssdServiceInstance service = new DnssdServiceInstance(fullServiceName, hostName, 2222);

await service.RegisterStreamSocketListenerAsync(new StreamSocketListener());

Console.ReadLine();

Replace 127.0.0.1 with real hostname, and register your service with RegisterStreamSocketListenerAsync

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.