Chapter 7. Network Programming with CFNetwork

One of the greatest strengths of the iPhone is its ability to deliver advanced functionality over an "always on" Internet connection. While the iPhone supports the usual set of standard C functions for network programming, Apple has also provided a framework, named CFNetwork, to provide name resolution, socket connectivity, and basic protocol communications.

You might consider using CFNetwork instead of standard BSD sockets if your application has a need for a run-loop; that is, you'll be able to use CFNetwork without spinning up threads or writing your own polling routines. The CFNetwork framework also adds an easy mechanism to handle reading and writing through socket streams, and supports common protocols such as HTTP and FTP out of the box. This allows you to focus on the more important aspects of your code, relieving you from the need to support individual protocols. CFNetwork is also supported in Leopard, meaning you can easily port your networking code to the desktop.

To use the CFNetwork framework, you'll need to add it to your Xcode project. Right-click on the Frameworks folder in your project, and then choose Add Framework. Navigate to the CFNetwork.framework folder, and then click Add.