How to register a service with Mono.ZeroConf?

2019-03-13 22:44发布

问题:

I'm trying to test the ZeroConf sample at http://www.mono-project.com/Mono.Zeroconf.

I'm running OpenSuse 11 and Mono 2.2.

My server code is:

using System;
using Mono.Zeroconf;

namespace zeroconftestserver
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            RegisterService service = new RegisterService ();
            service.Name = "test server";
            service.RegType = "_daap._tcp";
            service.ReplyDomain = "local.";
            service.Port = 6060;

            // TxtRecords are optional
            TxtRecord txt_record = new TxtRecord ();
            txt_record.Add ("Password", "false");
            service.TxtRecord = txt_record;

            service.Register();
            Console.WriteLine("Service registered!");
            Console.ReadLine();
        }
    }
}

But I can't find my registered service with the sample client browser code nor with mzclient.

Thanks!

回答1:

I've also tried to use the binaries provided at the Mono.Zeroconf project page and building the libs from source for use on Windows and was unable to publish a service that was findable by other clients. I tried both the example code on the site and the MZClient provided.

After a little more digging I found a project that used to the Mono.Zeroconf libs. By using the binaries checked into the Growl for Windows project at Google Code (which appear to be the latest version 0.9.0) I was able to successfully publish a findable service with both the sample code and MZClient.

So an apparent work around would be to grab the binaries (Mono.Zeroconf and Mono.Zeroconf.Providers.Bonjour) from that project and use those instead of the ones provided by the project.



回答2:

The binaries at mono-project.com/Mono.Zeroconf are out of date and still contain code that causes this problem. The most recent code (with all the fixes) is at this link but require you to compile the code yourself.



回答3:

I wasn't able to get a service published either. I looked through the code and there is a bug in Service.cs, the UPort setter:

this.port = (ushort) IPAddress.HostToNetworkOrder((int) value);  //overflow, port is always 0

It should be

this.port = (ushort) IPAddress.HostToNetworkOrder((short) value);


回答4:

Recompiling after updating the source from the following link solved the issue

https://github.com/mono/Mono.Zeroconf/tree/master/src



回答5:

He is using mzclient to test his Mono.Zeroconf code above. The entire point of Mono.Zeroconf is to provide cross platform, multiple mDNS provider support (Avahi and Bonjour).

There appears to be an issue with the EntryGroup DBus Avahi API and I am looking into it in Mono.Zeroconf. I'll post a solution here, as well as make a new Mono.Zeroconf release (I am the maintainer of the project) when I figure out the issue.



标签: c# mono zeroconf