Using Apple’s Bonjour service from .NET?
I have an iPhone app that publishes through Bonjour. The Mac counterpart works, they sync and exchange data. Now I have to port that little Mac app to Windows. I’ve decided to go with .NET (because that’s what I know).
The app is not complex, but I’m in the early stages. I need to browse/discover Bonjour services. For this task, I’ve downloaded Mono.Zeroconf and Apple’s latest SDK (which includes a couple of C# Samples).
I’m not really pasting code because I’m really copy/pasting the samples. In fact, Mono.Zeroconf has a MZClient.exe that can be used to test “all the API”.
My 1st test was -on the same box- open two cmd.exe and launch a MZclient registering a service and on the other, launch it and “discover it”.
It doesn’t work.
Here’s the server:
C:\MZ>MZClient -v -p "_http._tcp 80 mysimpleweb”
*** Registering name = 'mysimpleweb', type = '_http._tcp', domain = 'local.'
*** Registered name = ‘mysimpleweb’
On the other terminal:
c:\MZ>MZClient -v -t "_http._tcp"
Creating a ServiceBrowser with the following settings:
Interface = 0 (All)
Address Protocol = 开发者_如何学PythonAny
Domain = local
Registration Type = _http._tcp
Resolve Shares = False
Hit ^C when you're bored waiting for responses.
And that’s it. Nothing happens. I’ve of course tried with different services to no avail. Even played a little bit with that domain thing. Remember this is the same box. I tried on another computer, because this was a VM inside OSX, so I went ahead and tried on a “pure” win XP. Nothing.
note: I have Apple Bonjour Service (up and running) and also the Apple SDK (installed later).
Given that this didn’t work, I went ahead and decided to try the Apple SDK which has an Interop and a few pre-compiled samples (and its source code).
Short story, neither the mDSNBrowser.exe nor the SimpleChat.exe work/see/discover anything.
My box is a Win7 under Parallels, but that doesn’t seem to be affecting anything, given that the native XP exhibits the same problems.
What am I doing so awfully wrong?
I've used Zeroconf NetServices for Zeroconf inside of .NET. Assuming that you allow Bonjour through your firewall and that your network hardware allows multicast, the biggest issue always was the unreliability of the Apple Bonjour service. Routinely working code would fail, with the solution being to restart the Bonjour service. So, check your network hardware, check your firewall, but ultimately restart Bonjour a few times. It doesn't always work on the first, or second, or third try, etc.
Here are a couple of important references as the NuGet version, source version in Git and Growl Windows download currently seem to all have slightly different implementations. The NuGet pack didn't work for me, so I downloaded the source, made the recommended changes and recompiled.
How to register a service with Mono.ZeroConf?
http://bryanprice.info/2011/01/29/mono-zeroconf-on-windows/
精彩评论