gpt4 book ai didi

ios - iOS读取TXT记录

转载 作者:行者123 更新时间:2023-11-29 13:38:51 24 4
gpt4 key购买 nike

我正在慢慢地学习为网络编写代码并且已经走到了一个死胡同:我认为通过访问 nas 驱动器的 TXT 记录我能够看到它提供的卷,如下所述:

http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt

但是当我运行这段代码时:

browse = [[NSNetServiceBrowser alloc]init];
[browse setDelegate:self];
[browse searchForServicesOfType:@"_afpovertcp._tcp." inDomain:@"local"];

设置服务搜索和以下回调:

-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
{
NSLog(@"Found: %@",aNetService);
CFNetServiceRef aCFNetRef;
aCFNetRef = CFNetServiceCreate(kCFAllocatorDefault, (__bridge CFStringRef)[aNetService domain],(__bridge CFStringRef) [aNetService type], (__bridge CFStringRef)[aNetService name], 0);
CFStreamError error;
if (CFNetServiceResolveWithTimeout(aCFNetRef, timeOut, &error)) {
NSLog(@"CFNET TXT: %@",CFNetServiceGetTXTData(aCFNetRef));
}
}
NSLog(@"TXTRecord: %@",[NSNetService dictionaryFromTXTRecordData:[aNetService TXTRecordData]]);
if (!moreComing) {
[browse stop];
[refreshButton setEnabled:YES];
[self reloadInputViews];
}
}

nslog() 行显示找到的服务的 TXT 记录是空的:我得到一些类似的东西

Found: <NSNetService 0x6a90fd0> local. _afpovertcp._tcp. myLocalSVR
CFNET TXT: <00>
TXTRecord: (null)

有人能说我的代码是否正确,或者只是这里的本地 nas 不包含 TXT 记录 - 从我读到的内容来看,情况不应该如此。我还读到需要在发出 TXT 记录之前解决该服务,但我希望这就是 CFNetServiceResolveWithTimeout() 正在做的...

谢谢!

托德。

最佳答案

从您链接到的文档 ( http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt ),强调我的:

The intention of DNS-SD TXT records is to convey a small amount of useful additional information about a service. Ideally it should not
be necessary for a client to retrieve this additional information
before it can usefully establish a connection to the service. For a well-designed application protocol, even if there is no information
at all in the TXT record, it should be possible, knowing only the
host name, port number, and protocol being used, to communicate with
that listening process, and then perform version- or feature-
negotiation to determine any further options or capabilities of the
service instance
. For example, when connecting to an Apple Filing
Protocol (AFP) [AFP] server over TCP, the client enters into a
protocol exchange with the server to determine which version of AFP
the server implements, and which optional features or capabilities
(if any) are available.

我知道正确的做法是与发现的服务器建立 AFP session 以列出共享。

可以通过dns-sd -L查看NAS的TXT记录:

dns-sd -L name type domain
look up and display the information necessary to contact and use the named service: the hostname of the machine where that service is available, the port number on which the service is listening, and (if present) TXT record attributes describing properties of the service.

在我的本地网络上执行 _afpovertcp 查询我得到:

$ dns-sd -L mir _afpovertcp._tcp. local.
Lookup mir._afpovertcp._tcp..local.
1:14:40.948 mir._afpovertcp._tcp.local. can be reached at mir.local.:548 (interface 4) Flags: 1
1:14:40.948 mir._afpovertcp._tcp.local. can be reached at mir.local.:548 (interface 5) Flags: 1
1:14:40.948 mir._afpovertcp._tcp.local. can be reached at mir.local.:548 (interface 9) Flags: 1
1:14:40.948 mir._afpovertcp._tcp.local. can be reached at mir.local.:548 (interface 10) Flags: 1
1:14:40.948 mir._afpovertcp._tcp.local. can be reached at mir.local.:548 (interface 11) Flags: 1
1:14:40.948 mir._afpovertcp._tcp.local. can be reached at mir.local.:548 (interface 12)

希望这对您有所帮助。

关于ios - iOS读取TXT记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9748505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com