官术网_书友最值得收藏!

Introduction

The primary API behind Apple's low-level networking is the CFNetwork API.

The simplest way to describe CFNetworking is to say that it is an Apple-specific extension to the BSD socket API. The CFNetworking stack is based on and relies on the BSD socket API that was discussed in Chapter 1, BSD Socket Library. It is recommended that the reader understands the concepts discussed in Chapter 1, BSD Socket Library, prior to going through this chapter. While this chapter will focus primarily on CFNetworking for most of the recipes, we will also use NSHost and the system configuration framework for retrieving network address information and checking the network status recipes. The biggest advantage that BSD sockets have over CFNetwork is the compatibility with other forms of Unix. This is a pretty big advantage when you think of all the BSD socket code on the Internet that you can use. However, if your application is Apple-specific, it is recommended that you use CFNetwork wherever you can.

CFNetwork offers numerous advantages over BSD sockets. The biggest advantage is the run-loop integration. So if your application is run-loop-based, you will be able to implement network services without implementing numerous threads.

CFNetwork also contains a number of objects to help you implement specific protocols without having to know the implementation details about the protocols. This includes the CFFTP API to assist in implementing the FTP protocol, and CFHTTP to assist in implementing the HTTP protocol.

To understand CFNetworking, you should be aware of the main building blocks that make up CFNetwork, which are as follows:

  • CFSocket: It is an abstraction of the BSD socket covered in Chapter 1, BSD Socket Library. One of the main differences between the BSD socket and the CFSocket is that the CFSocket can be integrated with a run loop.
  • CFStream: It provides both read and write streams and makes it easy to exchange data not only across networks but also with files and memory objects.
  • CFSocketStream: It provides an extension for CFStream to work with network sockets.
  • CFFTP: It provides an API for communicating with FTP servers.
  • CFHTTP: It provides an API for communicating with HTTP servers.
  • CFHTTPAuthentication: It provides an API for responding to HTTP authentication challenges.
主站蜘蛛池模板: 柯坪县| 澜沧| 长沙县| 长春市| 泰安市| 衡阳市| 南宁市| 驻马店市| 镶黄旗| 娄底市| 临桂县| 宣化县| 卓尼县| 郁南县| 葫芦岛市| 东丽区| 庆元县| 玉环县| 宽甸| 新泰市| 遂平县| 邵东县| 甘洛县| 类乌齐县| 浦江县| 小金县| 手游| 麻城市| 揭东县| 乌恰县| 布尔津县| 上犹县| 聂拉木县| 观塘区| 新源县| 渝北区| 仪陇县| 正安县| 饶阳县| 潞城市| 浙江省|