[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