"Reading notes" iOS network-Underlying network

Source: Internet
Author: User

On iOS, there is a library called core Foundation networking or cfnetwork, which is a lightweight package for the original socket, but it quickly becomes cumbersome for most common scenarios. Finally, another layer (nsstream) is added to encapsulate the cfnetwork and act as the most basic OBJECTIVE-C network API. Classes that are more familiar to you (such as nsurlconnection and UIWebView) are very easy to use and can do a lot of things with very little code, thanks to the solid foundation that these underlying libraries provide.

One, BSD Socket

Apple does not recommend this approach because the original socket does not have access to the operating system's built-in network features, such as a system-wide VPN. Even worse, initializing the socket connection does not automatically turn on the device's Wi-Fi or cellular radio. The radio will turn off intelligently to conserve battery power, and any communication connection will fail unless the radio is activated by other network routines. Cfnetwork the BSD socket package activates the device's radio, so in almost all scenarios, we recommend the use of Cfnetwrok, not the BSD socket.

Two, cfnetwork

The CFNETWORKD is located in the upper layer of the frame hierarchy and is a lightweight package for BSD sockets.

Three, Nsstream

The goose bumps along the frame level are nsstream, which is the Objective-c wrapper for the Cfnetwork API.

Four, summarize.

As the frame level goes up, the code is shorter and simpler, but you lose some power because each abstraction layer hides the original network socket that actually performs the communication.

Reference: "iOS network advanced programming-iphone and ipad Enterprise application Development"

"Reading notes" iOS network-Underlying network

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.