问题
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