Chapter 8

Low-Level Networking

WHAT’S IN THIS CHAPTER?

  • Deciphering BSD Sockets
  • Implementing CFNetwork APIs
  • Developing with NSStream

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

You can find the wrox.com code downloads for this chapter at www.wrox.com/remtitle.cgi?isbn=9781118362402 on the Download Code tab. The code for this chapter is found in one example project: Low-Level Networking.zip.

Every complex computer system is built on one or more layers of abstraction, and low-level networking is no exception. At the root of the networking house of cards is the humble Berkley, or BSD, socket. It performs the most basic task of networking: sending and receiving a series of bits. Because it takes a fair amount of code to properly send a single byte and because that same logic is repeated for every single socket, libraries were built to encapsulate that logic so it can be reused by anyone. On iOS the resulting library is called Core Foundation networking, or CFNetwork, which is a lightweight wrapper around raw sockets, but soon became too cumbersome for the most common use cases. Eventually another layer, NSStream, was added as a wrapper around CFNetwork and was intended to be the most basic Objective-C networking API. More familiar classes, such as NSURLConnection and UIWebView, are easy to use and accomplish a lot with minimal code because of the solid foundation these three low-level libraries provide. This chapter gives working examples of each library connecting to the same server ...

Get Professional iOS Network Programming: Connecting the Enterprise to the iPhone and iPad now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.