问题描述
我要添加引用<一个href=\"https://developer.apple.com/library/mac/#sample$c$c/DNSSDObjects/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011371\"相对=nofollow> DNSSDObjects 来在MonoTouch的项目,特别是DNSServiceResolve对象。
I want to add reference to DNSSDObjects to a project in MonoTouch, specifically DNSServiceResolve object.
我想在MonoTouch的项目访问DNSServiceResolve,但无法找到任何地方的类。
I want to access DNSServiceResolve in a MonoTouch project but cant find that class anywhere.
那怎么可以呢?
推荐答案
我从dns_sd.h与P /调用工作的功能。大多数的定义在项目zeroconfignetservices [1]已经完成,特别是在该文件mDNSImports.cs。而不是引用 dnssd.dll
,它是 /usr/lib/system/libsystem_dnssd.dylib
iOS上。
I got the functions from dns_sd.h working with P/Invokes. Most of the definitions were already done in the project zeroconfignetservices [1], specifically in the file mDNSImports.cs. Instead of referencing dnssd.dll
, it is /usr/lib/system/libsystem_dnssd.dylib
on iOS.
因此,例如,对于DNSServiceQueryRecord的定义是:
So for example, the definition for DNSServiceQueryRecord would be:
[DllImport("/usr/lib/system/libsystem_dnssd.dylib")]
public static extern DNSServiceErrorType DNSServiceQueryRecord(out IntPtr sdRef,
DNSServiceFlags flags,
UInt32 interfaceIndex,
[MarshalAs(
UnmanagedType.CustomMarshaler,
MarshalTypeRef = typeof(Utf8Marshaler))] String fullname,
DNSServiceType rrType,
DNSServiceClass rrClass,
DNSServiceQueryReply callBack,
IntPtr context);
并为SRV记录的查询将如下所示:
public void DoDnsLookup()
{
IntPtr sdRef;
var result = DNSServiceQueryRecord(
out sdRef,
DNSServiceFlags.LongLivedQuery,
0,
"_xmpp-client._tcp.gmail.com",
DNSServiceType.SRV,
DNSServiceClass.IN,
DnsServiceQueryReply,
IntPtr.Zero
);
if (result == DNSServiceErrorType.NoError)
{
DNSServiceProcessResult(sdRef);
DNSServiceRefDeallocate(sdRef);
}
}
//see [2] why this method is static and the attribute
[MonoPInvokeCallback(typeof(DNSServiceQueryReply))]
public static void DnsServiceQueryReply(
IntPtr sdRef,
DNSServiceFlags flags,
UInt32 interfaceIndex,
DNSServiceErrorType errorCode,
[MarshalAs(
UnmanagedType.CustomMarshaler,
MarshalTypeRef = typeof(Utf8Marshaler))] String fullname,
DNSServiceType rrType,
DNSServiceClass rrClass,
UInt16 rdLength,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 7)]byte[] rData,
UInt32 ttl,
IntPtr context)
{
if (result == DNSServiceErrorType.NoError)
{
// process returned DNS data in rData
// a useful library for this could be Bdev.Net.Dns [3]
}
}
所有的类,枚举,等等。这里没有定义来自[1]。
All the classes, enums, etc. not defined here are from [1].
参考文献:
- dnslookup。codeplex.com
这篇关于谈到在MonoTouch的dns_sd.h和DNSServiceResolve DNSSDObjects的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!