0

I am familiar with several of the different ways to do TCP connections (CFNetwork, BSD Sockets, etc.) but I recently discovered NSStream has "XXXwithURL:" APIs which allow TCP connections only using NSStream. Is there any advantage to creating connections this way?

Also, what is the connection between NSStream and CFStream? It looks like they are toll-free bridged but does that mean NSStream is built on top of CFStream?

Locksleyu
  • 5,192
  • 8
  • 52
  • 77
  • Also: "does that mean NSStream is built on top of CFStream?" <-- NO. It means that NSStream == CFStreamRef. –  Jul 18 '12 at 19:33
  • Thanks for the correction, I'll fix that now. Also thanks for clarification about references being equal. I'm still curious why anyone would use NSStream over the other various APIs for TCP networking. – Locksleyu Jul 18 '12 at 19:42
  • 1
    because people are lazy -- some think NSStream is easier to learn jsut because it's OO, whereas I think it's even more complicated than good ol' BSD sockets. –  Jul 18 '12 at 19:44
  • Interesting comment, in what way is it more complicated? – Locksleyu Jul 18 '12 at 20:00
  • I generally find the learning curve of most of Apple's frameworks longer than other similar (non-Apple-but-Unix) solutions, for example (concerning networking again), it's quite painful to do a HTTP POST request using the NSURL* API, but with my favourite (plain C) library, libCURL, it's literally 4 or 5 SLOC. –  Jul 18 '12 at 20:11
  • 1
    I have to vote in disagreement with H2CO3. *In general*, Apple's objective-C APIs are much easier to use, and better documented than low-level UNIX or POSIX APIs. If you've had a lot of experience with BSD sockets, then it's not hard to use ... but, that's a big **if**. There's a reason that object-oriented APIs have *mostly* replaced low-level APIs in app programming. – Nate Jul 18 '12 at 22:21

0 Answers0