[Reading Notes] iOS network-underlying network, Reading Notes ios

Source: Internet
Author: User

[Reading Notes] iOS network-underlying network, Reading Notes ios

On iOS, there is a library called Core Foundation networking or CFNetwork, which is a lightweight encapsulation of the original Socket, but it quickly becomes very heavy for most common scenarios. Finally, an additional layer (NSStream) is added to encapsulate the CFNetwork and serve as the most basic Objective-cnetwork API. Classes that you are more familiar with (such as NSURLConnection and UIWebView) are very easy to use and can accomplish many things through a small amount of code, these are all implemented based on the solid foundation provided by these underlying libraries.

1. BSD Socket

This method is not recommended by Apple because the original Socket cannot access the built-in network features of the operating system (such as system-range VPN ). Even worse, initializing the Socket connection does not automatically enable the Wi-Fi or cellular radio of the device. The radio is intelligently disabled to save battery power. Any communication connection will fail unless the radio is activated during other network periods. CFNetwork encapsulation of BSD Socket can activate the device's radio. Therefore, CFNetwrok is recommended in almost all scenarios, instead of BSD Socket.

Ii. CFNetwork

CFNetworkd is located at the upper layer of the framework level and is a lightweight encapsulation of BSD Socket.

Iii. NSStream

Starting from the framework layer, the NSStream is an Objective-C package for CFNetwork APIs.

Iv. Summary.

The higher the framework hierarchy, the shorter the code, the simpler the Code. However, you lose some capabilities because each abstraction layer hides the original network Socket for actual communication execution.

 

Reference: iOS network advanced programming-enterprise application development for iPhone and iPad

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.