开发者

How to resolve an address with MonoTouch.Foundation.NSNetService?

I am currently developing an iPad application. I want this to communicate with a Windows c# application using WCF, and discovery over BonJour.

I have already made the windows/c# part, using Mono.ZeroConf library, and tested that it works as supposed on Windows.

Now when I try to get my MonoTouch application discover the Windows application, all goes fine until I need to resolve the address. I simply can't figure out what is wrong.

I have the following code in my iPad app.

NSNetServiceBrowser browser = new NSNetServiceBrowser();
browser.FoundService += delegate(object sender, NSNetServiceEventArgs e){
    e.Service.AddressResolved += delegate(object service, EventArgs e1){

        //No matter how I treat the Bytes here it resolves to me as 8.135.207.208
        //When it was supposed to resolve to some 172.x.x.x ip. 
        long address = ((NSNetService)service).Addresses[0].Bytes.ToInt64();
    };
    e.Service.Resolve();
};
browser.SearchForServices("_myService._tcp", "local");

So my question is, how am I supposed to treat the NSData objects in the Addresses 开发者_开发百科array to resolve them correct.

I have tried searching, but can't seem to figure out.

All the other properties of the resolved service is correct, like name, port, etc.

I hope some of you have been here, and can provide me an answer.

Best regards /Anders


The data in the Addresses you receive is NSData in an NSArray. The description for the delegate itself says it is a collection of sockaddr objects (plain C struct). So definitely not a Int64 as is, but a pointer to sockaddr object.

The way it is done in MT is a bit different then. You received the delegate to the NSNetService, and now you have to wait for the service to resolve the address, this is done by another resolving.

I usually store the NSNetService returned by the NSNetServiceBrowser delegate and then wait until the address is resolved, once this is done, it is then when I use the service as it is already initialized and I do not care about the address itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜