Search code examples
c#.net-4.0monobonjourzeroconf

Mono.Zeroconf service port is always set to 0


I am trying to use Mono.ZeroConf for service discovery. I can discover services normally, but port of every service is always set to 0 instead of actual value.

I am using .NET 4, and ZeroConf 0.9.0, here is my code:

public MainWindow()
{
    serviceBrowser = new ServiceBrowser();
    serviceBrowser.ServiceAdded += ServiceAdded;
    serviceBrowser.Browse(0, AddressProtocol.Any, "_http._tcp.", "local");
}

private void ServiceAdded(object o, ServiceBrowseEventArgs args)
{
    Console.WriteLine("*** Found name = '{0}', type = '{1}', domain = '{2}'",
    args.Service.Name,
    args.Service.RegType,
    args.Service.ReplyDomain);
    args.Service.Resolved += ServiceResolver;

    if (args.Service.Name.Equals("MyService") && 
        args.Service.RegType.Equals("_http._tcp."))
    {
        args.Service.Resolve();
    }
}

private void ServiceResolver(object o, ServiceResolvedEventArgs args)
{
    IResolvableService service = o as IResolvableService;
    Console.Write("*** Resolved name = '{0}', host ip = '{1}', hostname = {2}, 
    port = '{3}', " + "interface = '{4}', address type = '{5}'",
    service.FullName, service.HostEntry.AddressList[0],
    service.HostEntry.HostName, service.Port,
    service.NetworkInterface, service.AddressProtocol);
}

When I use MZClient 0.8.0 to discover services all ports values are as expected, but when I use 0.9.0, same thing happens.

How can I get proper port value? Is it due to some bug in version 0.9.0, or something else?


Solution

  • This is due to a bug in Mono.Zeroconf, which is fixed in this pull request.

    You'll need to build the library yourself until the pull request is accepted and the Nuget package is published again.