本文介绍了使用 iPhone SDK 查找 SRV 记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 或 Mac OS X 终端中,如果您键入...

In either a Windows or Mac OS X terminal if you type...

nslookup -type=SRV _xmpp-server._tcp.gmail.com

...(例如)您将收到一堆与不同谷歌聊天服务器相关的 SRV 记录...

... (for example) you will receive a bunch of SRV records relating to different google chat servers..

有没有人在这方面有任何经验,并且可能知道如何使用 iPhone SDK 提供这些信息(主机名、端口、权重、优先级)?我已经尝试过 Bonjour 课程,但还没有运气..

Does anyone have any experience in this area and possibly know how to service this information (hostname, port, weight, priority) using the iPhone SDK? I have experimented with the Bonjour classes, but as yet have had no luck..

谢谢!

推荐答案

我相信您需要使用 DNSServiceDiscovery 框架.我没有 iPhone SDK,但 Google 搜索表明它可以在 iPhone 上使用.

I believe you need to use the DNSServiceDiscovery framework. I don't have the iPhone SDK, but a Google search suggests that it is available on the iPhone.

有关完整的 API 详细信息,请参阅 Apple 开发人员网站.

我也包含了一些(不完整的)示例代码:

I've included some (incomplete) sample code too:

#include <dns_sd.h>

int main(int argc, char *argv[])
{
   DNSServiceRef sdRef;
   DNSServiceErrorType res;

   DNSServiceQueryRecord(
     &sdRef, 0, 0,
     "_xmpp-server._tcp.gmail.com",
     kDNSServiceType_SRV,
     kDNSServiceClass_IN,
     callback,
     NULL
  );

  DNSServiceProcessResult(sdRef);
  DNSServiceRefDeallocate(sdRef);
}

您需要提供自己的回调函数,并注意发送到回调的 rdata 字段是有线格式的,因此您必须解码来自 SRV 的原始数据自己记录字段.

You'll need to provide your own callback function, and note that the rdata field sent to the callback is in wire-format, so you'll have to decode the raw data from the SRV record fields yourself.

这篇关于使用 iPhone SDK 查找 SRV 记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 20:13