IOS network programming hierarchy model and ios Network Programming Model

Source: Internet
Author: User

IOS network programming hierarchy model and ios Network Programming Model

The Network Programming hierarchy of iOS is also divided into three layers:

 

  • Cocoa layer: NSURL, Bonjour, Game Kit, WebKit
  • Core Foundation layer: C-based CFNetwork and CFNetServices
  • OS layer: C-based BSD socket

Cocoa layer: it is the top-layer Objective-C-based API, such as URL access, NSStream, Bonjour, and GameKit. This is a common API in most cases. The Cocoa layer is implemented based on the Core Foundation.

Core Foundation layer: because the direct use of socket requires more programming work, Apple simply encapsulates the OS-layer socket to simplify programming tasks. This layer provides CFNetwork and CFNetServices. CFNetwork is based on CFStream and CFSocket.

OS layer: the underlying BSD socket provides maximum control over network programming, but programming is also the most. Therefore, Apple recommends that we use Core Foundation and APIs above for programming.

CFNetwork

CFNetwork is located at the underlying layer, but it efficiently handles protocol stack operations. BSD socket provides some standard objects for easy operations, such as communicating with FTP and HTTP servers and parsing DNS host addresses. CFNetwork is based on BSD socket. Similarly, some cocoa classes, such as NSURL, use the standard network protocol to communicate with the server, which is based on CFNetwork. In addition, WebKit is a cocoa class that displays the network content in the window. Both NSURL and WebKit are on top of each other, and you need to handle the network protocol on your own.


Is the structure of the CFNetwork framework and Core Foundation framework:

CFSocket API and CFStream API are the foundation of CFNetwork. Sockets are the basis of network communication. sockets can connect to the network or another local socket and allow data transmission. The most common Socket abstraction is BSD Socket. CFSocket is the abstraction of BSD Socket. CFSocket contains almost all functions of BSD Socket, and integrates Socket into run-loop. CFSocket can process any socket or even stream-based socket.
CFStream API provides easy and device-independent Data Reading and Writing capabilities. You can create a stream for memory, files, and network (using sockets) data. You can use stream instead of writing all data to the memory immediately.
Stream is a byte sequence that is continuously transmitted in the established channel. Steam is unidirectional, and it is necessary to establish both input (read) stream and output (write) stream. Except for the file-based stream, once the data in the stream is consumed, it cannot be found.
CFStream is an abstraction of these streams and provides two CFType types: CFReadStream and CFWriteStream, both of which comply with the Core Foundation API specifications.
As shown in the figure, CFStream is based on CFSocket, and CFStream is the basis of CFFTP and CFHTTP. CFStream is not part of the CFNetwork, but part of the Core Foundation.

CFNetwork APIs can be split into many independent APIs that can be used independently and can be used together.

  • CFFTP API
  • CFHTTP API
  • CFHTTPAuthentication API
  • CFHost API
  • CFNetServices API
  • CFNetDiagnostics API

ASIHTTPRequest

Using the HTTP network request API in the iOS SDK is quite complex and tedious to call. ASIHTTPRequest is an API that encapsulates the CFNetwork API and is very simple to use, written in Objective-C, it can be well applied to Mac OS X systems and iOS platform applications. ASIHTTPRequest is applicable to basic HTTP requests and interaction with REST-based services.

ASIHTTPRequest is powerful and has the following features:

  • L a simple interface can be used to submit data to and obtain data from the server.
  • L The downloaded data can be stored in the memory or directly stored in the disk.
  • L upload local files to the server
  • L convenient access and operation of requests and returned Http header information
  • L get the upload or download progress information to provide a better experience for the Application
  • L supports uploading or downloading queues and obtains queue progress information.
  • L supports basic, digest, and NTLM identity authentication. Authorization creden are automatically maintained in the same session and can be stored in the Keychain (password management system for Mac and iOS operating systems ).
  • L Cookie support
  • L when the application (iOS 4 +) runs in the background, the request can continue to run
  • L supports GZIP compressed data
  • L The built-in ASIDownloadCache class can cache the data returned by the request, so that the cached data results can be returned even if there is no network.
  • L ASIWebPageRequest-you can download the complete webpage, including the contained webpage, style sheet, script, and other resource files, and display them in UIWebView/WebView. Pages of any size can be cached indefinitely, so that they can be browsed offline even if there is no network.
  • L support client certificates
  • L support initiating Http requests through proxy
  • L supports bandwidth restrictions. On the iOS platform, you can automatically decide whether to limit the bandwidth based on the current network conditions. For example, you can use the WWAN (GPRS/Edge/3G) Network Time limit system, but do not apply any restrictions when using WIFI.
  • L supports resumable upload
  • L support synchronous and asynchronous requests

Official Website: http://allseeing-i.com/ASIHTTPRequest. You can download the latest source code and obtain relevant information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.