NSStream - reverse DNS lookup error

柔情痞子 提交于 2019-12-11 08:23:05

问题


I have to open an NSStream to a wifi access point that has only a numerical address, not a name. It takes NSStream 30-40 seconds to open a socket. In experimenting, i found that telnet-ing to the AP from a windows box was instantaneous, but on a mac, connecting the same 30-40 seconds. in researching telnet, i found that the implementation is a little different on a mac, in that it by default tries to to a name lookup. reading the manual page for telnet, i found: -N Prevents IP address to name lookup when destination host is given as an IP address.

when I used "telnet -N IP-address port", my connection was instantaneous! I suspect that this same problem is causing the delay in my NSStream connection. Is there any way to do the equivalent of setting the"-N" flag in NSStream?


回答1:


It looks like NSHost is not available on Cocoa Touch, so you cannot force a host with a given address, though I don't know if that negates the need for a dns lookup.

This problem has been around since 2005, though this might not apply to Cocoa Touch libraries. In any case there is no given solution:

  • http://developer.apple.com/library/ios/#DOCUMENTATION/Networking/Conceptual/CFNetwork/Concepts/Concepts.html#//apple_ref/doc/uid/TP30001132-CH4-SW10

  • http://developer.apple.com/library/ios/#DOCUMENTATION/CoreFoundation/Reference/CFSocketRef/Reference/reference.html#//apple_ref/doc/c_ref/CFSocketCreate



来源:https://stackoverflow.com/questions/9961791/nsstream-reverse-dns-lookup-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!