I recommend that you avoid using
CFSockethas many sharp edges. The alternative is pretty simple: Do this part of the job using BSD Sockets. Now, BSD Sockets has lots of sharp edges as well, but they’re well-documented sharp edges (-:
The main complication with replacing
CFSocketwith BSD Sockets is the async connect. Fortunately dispatch event sources make that relatively easy.
Finally, once you have a connect BSD Socket I recommend that you wrap that in an
NSStreampair rather than a
CFStreampair, because the
NSStreamAPI is substantially easier to use. You do this by exploiting the toll-free bridge between the types, that is, call
CFStreamCreatePairWithSocketand cast the resulting values to
NSOutputStream. You can steal the basic code outline from QA1652 Using NSStreams For A TCP Connection Without NSHost (although that uses
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
Thanks Quinn, using BSD socket worked in this scenario.
I had to wait on socket to become writable( using select() call) before opening the streams.
I will see if dispatch event sources make it more simpler to handle the async connect.
Looks like there is no way to select network interface at application level.