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.
Basic Sockets Programming
The most common use of the CFNetwork framework is to communicate across network sockets. A socket is a single channel of communication between two endpoints; think of it as the string connecting two tin cans. Sockets can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access