iOS Network programming model

Source: Internet
Author: User

Http://www.cnblogs.com/ydhliphonedev/p/3240772.html

    • Cocoa Layer: Nsurl,bonjour,game Kit,webkit
    • Core Foundation layer: C-based cfnetwork and cfnetservices
    • OS layer: BSD socket based on C

Cocoa layer: Is the top-level Objective-c-based API, such as URL access, Nsstream,bonjour,gamekit, and so on, which is commonly used in most cases API. The COCOA layer is implemented based on the Core Foundation.

Core Foundation layer: Because the direct use of the socket requires more programming work, Apple's socket on the OS layer is simply encapsulated to simplify programming tasks. This layer provides cfnetwork and cfnetservices, where Cfnetwork is also based on Cfstream and Cfsocket.

OS layer: The lowest-level BSD socket provides maximum control over network programming, but it also has the most programming effort. Therefore, Apple recommends that we use the Core Foundation and the API of the above layer to program.

Cfnetwork

Cfnetwork is located on the ground floor, but handles the operation of the protocol stack efficiently. BSD sockets provide a number of standard objects for easy operation, such as communicating with FTP and HTTP servers, and resolving DNS host addresses. And Cfnetwork is based on BSD sockets. Similarly, some cocoa classes, such as NSURL, use standard network protocols to communicate with the server, which is based on Cfnetwork. In addition, WebKit is some cocoa class that displays the network content in the window. and Nsurl and WebKit are above the high-level, to handle the network protocol on their own.


is a structure diagram of the Cfnetwork framework and the Core Foundation framework:

The Cfsocket API and Cfstream API are the basis of cfnetwork. Sockets are the basis of network communication, and sockets can be connected to a network or another local socket and allow data to be transmitted. The most common socket abstraction is the BSD socket. Cfsocket is also a BSD socket abstraction. The cfsocket contains almost all the functionality of the BSD socket and incorporates the socket into the run-loop. Cfsocket can handle any socket, even stream-based socket.
The Cfstream API provides easy device-independent read and write data capabilities. You can create a stream for memory, file, network (using sockets) data, and you can use stream without having to write all of your data to memory immediately.
Stream, which is a sequential sequence of bytes transmitted in a communication channel. Steam is unidirectional and it is necessary to establish the input (read) stream and the output (write) stream. In addition to the file-based stream, the data in the stream cannot be found once it is consumed.
Cfstream is an abstraction of these streams and offers two types of Cftype: Cfreadstream and Cfwritestream, all conforming to the core Foundation API specification.
As can be seen from the figure, Cfstream is based on Cfsocket, and Cfstream is the basis of cfftp and cfhttp. But Cfstream is not part of the cfnetwork, but part of the core Foundation.

The Cfnetwork API can be split into a number of standalone 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 complicated and cumbersome to call, ASIHTTPRequest is a set of APIs that encapsulates the Cfnetwork API and is very simple to use, written in Objective-c, can be very well applied in Mac OS x systems and iOS platform applications. ASIHTTPRequest applies to basic HTTP requests, and to the interaction between rest-based services.

ASIHTTPRequest features are very powerful, the main features are as follows:

    • • The task of submitting data to the server and obtaining data from the server is done through a simple interface
    • L downloaded data that can be stored in memory or stored directly on disk
    • L can upload local file to server
    • L can easily access and manipulate the request and return HTTP header information
    • L can get the progress information to upload or download, provide a better experience for the application
    • L support upload or download queue, and can get progress information of queue
    • Support for Basic, Digest, and NTLM authentication, authorization credentials are automatically maintained in the same session, and can be stored in keychain (password management system for Mac and iOS operating systems)
    • L Support Cookies
    • When the app (IOS 4+) is running in the background, the request can continue to run
    • L Support gzip Compressed data
    • The built-in Asidownloadcache class allows you to cache the data returned by the request so that even if no network can return the cached data results
    • L asiwebpagerequest– can download the full page, including the page, style sheet, script and other resource files, and display in Uiwebview/webview. Pages of any size can be cached indefinitely, so that you can browse offline even if you don't have a network
    • L Support client Certificate
    • • Support for initiating HTTP requests through proxies
    • L Support Bandwidth throttling. On the iOS platform, you can automatically decide whether to limit bandwidth based on current network conditions, such as when using a Wwan (gprs/edge/3g) network, and without any restrictions when using WiFi
    • L Support for continuous transmission of breakpoints
    • L Support synchronous and asynchronous requests

Official website: http://allseeing-i.com/ASIHTTPRequest/. Can be downloaded from the above to the latest source, as well as to obtain relevant information.

iOS Network programming model

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.