About TCP/UDP in iOS

Source: Internet
Author: User

About TCP/UDP in iOS
TCP (Transmission Control Protocol) and UDP (User datasync Protocol) Protocols belong to the transport layer Protocol. The User Data protocol (UDP) provides only application process addressing and simple error detection, and does not provide other functions. TCP (Transport Control Protocol) is a connection-oriented Protocol, that is, a reliable connection must be established with the other party before sending and receiving data. A TCP connection can be established only after three "conversations". The process is very complex. Only a simple process of the three conversations is described: host A sends A connection request packet to host B: "Can I send you data? ", This is the first conversation; host B sends A packet to host A that agrees to the connection and requires synchronization (synchronization means that two hosts are sending, receiving, and coordinating): "Yes, when will you send it? ", This is the second conversation. host a sends another packet to confirm that host B's request is synchronized: "I will send it now, let's proceed !", This is the third dialogue. The purpose of the three "dialogs" is to synchronize the transmission and receipt of data packets. After the three "dialogs", host A formally sends data to host B. 1. how the uploaded data interacts with the backend server. The interaction between the backend and front-end is achieved through network interfaces. upload data through an http request. After iOS9 is an https request, you need to convert the data to the data type, splice the data to the POST Request body, and send the data together to the server. The format returned by the server is generally returned in json format. It has the advantage that the transmitted data is relatively small, and the ios client is easy to parse. As for the server, you can have multiple options, such as asp.net, java, and php. 2. Differences between the two request methods: 1. For GET requests, the requested data will be appended to the URL? Splits the URL and transmits data. Multiple parameters are connected. The URL encoding format uses ASCII encoding instead of uniclde, that is, all non-ASCII characters must be encoded before transmission. POST request: the POST request places the requested data in the packet body of the HTTP request package. The above item = bandsaw is the actual data transmission. Therefore, the GET request data is exposed in the address bar, while the POST request does not. 2. The size of transmitted data is not limited by the URL Length and data size in the HTTP specification. However, in actual development, specific browsers and servers have limited URL length. Therefore, when using GET requests, data transmission is limited by the URL length. For POST, since it is not a URL-based value transfer, it is theoretically not limited, but in fact each server will limit the size of POST-submitted data. Apache and IIS have their own configuration. 3. The security of POST is higher than that of GET. Security here refers to real security. Unlike the security mentioned in GET, the security mentioned above only does not modify server data. For example, in the login operation, the GET request, user name and password are exposed and then URL, because the login page may be cached by the browser and others can view the browser's historical records, at this time, the user name and password can be easily obtained by others. In addition, data submitted by GET requests may cause Cross-site request frogery attacks 9. What are the differences between Get and Post in HTTP? Which is safer to use? Http defines different methods for interaction with the server. There are four basic methods: GET, POST, PUT, and DELETE. The full name of a URL is a resource descriptor. We can think that a URL address is used to describe resources on a network, while GET, POST, PUT, DELETE corresponds to the query, modify, add, and DELETE operations on this resource. Here, you should have a rough understanding. GET is generally used to obtain/query resource information, while POST is generally used to update resource information. I. Differences in Principles 1. According to HTTP specifications, GET is used for information retrieval and should be secure and idempotent. 2. According to HTTP specifications, POST indicates requests that may modify resources on the server. 3. How to handle the concurrency of multiple network requests through GCD and NSOperationQueue to control concurrency 92. What is the difference between TCP and UDP? TCP connection-oriented, reliable transmission (ensuring data correctness and data sequence), used to transmit a large amount of data (stream mode), slow speed, and costly connection establishment (time, system Resources ). UDP is designed for non-connection, unreliable transmission, and is used to transmit a small amount of data (Packet Mode) with high speed. 82. methods used for network communication (AFNetworking was mentioned by 100% of people ...) how to handle the concurrency of multiple network requests 1) directly using socket 2) AFNetworking uses concurrent queues in multiple threads to process concurrent network requests. 83. how to improve performance in network requests how to ensure security in network requests iOS may cause data leakage during Data Transmission, the client generally uses encryption to ensure data security when making network requests. After iOS9, Apple uses Https to protect data security. 11. What is socket? (1) socket is a set of interfaces for tcp and udp protocols. HTTP: Simple Object Access Protocol, which corresponds to the application layer. HTTP is a TCP protocol based on tcp connections. It corresponds to the transport layer IP protocol, it mainly solves the problem of how data is transmitted over the network, while HTTP is the application layer protocol, which mainly solves the problem of how to package data. Socket is the encapsulation of TCP/IP protocol. Socket itself is not a protocol, but an interface (API) called. Through Socket, we can use TCP/IP protocol. The emergence of Socket only makes it easier for programmers to use the TCP/IP protocol stack. It is an abstraction of the TCP/IP protocol, thus forming some of the most basic function interfaces we know. Http connection: an http connection is a short connection. When a client sends a request to the server, the connection will be disconnected after the server responds. socket Connection: A socket connection is a persistent connection, theoretically, once a connection is established between the client and the server, the connection will not be automatically disconnected. However, due to various environmental factors, the connection may be disconnected, for example, when the server or client host is down and the network is faulty, or there is no data transmission between the two for a long time, the network firewall may disconnect the connection to release network resources. (2) Establishing a Socket connection requires at least one pair of sockets. In short, the Socket is a communication convention between the two parties, and the related functions in the Socket are used to complete the communication process. One runs on the client, called ClientSocket, And the other runs on the server, called ServerSocket. The connection process between sockets is divided into three steps: server listening, client requests, and connection confirmation. 1. Server listening: the server socket does not locate the specific client socket, but is waiting for connection. It monitors the network in real time and waits for client connection requests. 2. Client request: the client socket initiates a connection request, and the target is the server socket. Therefore, the client socket must first describe the socket of the server to be connected, point out the address and port number of the socket on the server, and then submit a connection request to the socket on the server. 3. Connection Confirmation: when the server socket monitors or receives a connection request from the client socket, it responds to the request from the client socket and creates a new thread, send the description of the server socket to the client. Once the client confirms the description, both parties establish a connection. The server socket continues to be in the listening status, and continues to receive connection requests from other client sockets. The core code of AFHTTPRequestOperation is different from that of the NSURLConnection object. The NSURLSession objects can be configured separately for setting the shared application scope, such as session management, Cache Policy, Cookie storage, and URL protocol. Use a specific configuration to initialize a session. It can send tasks to obtain data and upload or download files. In AFNetworking 2.0, AFHTTPRequestOperation may be used to create an independent network request with no additional overhead to obtain data. NSURLSession requires more overhead to obtain the data to be requested. 41. Differences between the new AFNetworking version and earlier versions. NSURLSession uses (1) NSURLConnection APIs have been discarded. The classes below the class have been discarded from AFNetworking 3.0 :? AFURLConnectionOperation? AFHTTPRequestOperation? The class modified by AFHTTPRequestOperationManager contains the internal implementation of NSURLConnection-based APIs. They have been reconstructed using NSURLSession :? UIImageView + AFNetworking? UIWebView + AFNetworking? The core code of UIButton + AFNetworking (2) AFHTTPRequestOperation is different from that of the NSURLConnection object. The setting of each shared application scope includes session management, Cache Policy, Cookie storage, and URL protocol, these NSURLSession objects can be configured separately. Use a specific configuration to initialize a session. It can send tasks to obtain data and upload or download files. In AFNetworking 2.0, AFHTTPRequestOperation may be used to create an independent network request with no additional overhead to obtain data. NSURLSession requires more overhead to obtain the data to be requested. (3) The Migration image download of UIKit has been restructured to comply with the AlamofireImage architecture and the new AFImageDownloader class. The role of downloading images in this category is the UIButton and UIImageView categories, and provides some methods that can be customized when necessary. Category, the actual method for downloading remote images has not changed. The category of UIWebView is reconstructed to use AFHTTPSessionManager as its network request. The category of UIAlertView is discarded from the category of UIAlertView after AFNetworking 3.0. There is no plan to provide the UIAlertController class, because this is the logic that the application should process, not the library. NSURLSession using NSURLSession is a group of relatively easy-to-use network APIs provided by ios sdk. It includes several parts: NSURLRequest, NSURLCache, NSURLSession, NSURLSessionConfiguration, and NSURLSessionTask. 6. In the case of no network connection, how does one implement 10 records each time when I pull and load 10 records from the local database sqlite? Determine the network condition. When there is no network, 10 data records are retrieved from the database through the predicate settings when pulling up and loading, and the interface is refreshed. 20. What are the advantages of https in the differences between http and https? Http is super? Text transmission protocol. What is the information? Https is a secure ssl encrypted transmission protocol. Https phase? It is safer than http. The https protocol needs to request a certificate from the ca ,? Generally, there are very few free certificates and you need to pay for them. Http and https enable? Is a completely different connection used? Method? End ?? Or not? The former is 80, and the latter is 443. The http connection is simple, right? Is stateless HTTPS constructed by SSL + HTTP? Encrypted row transmission ,? Authenticated? What is the network protocol? It is more secure than http. methods used for network communication (AFNetworking was mentioned by 100% of people ...) how to handle the concurrency of multiple network requests 1) directly using the socket method 2) AFNetworking uses the concurrent queue in multiple threads to process the concurrent requests of the network 42. how to improve performance in network requests how to ensure security in network requests iOS may cause data leakage during Data Transmission, the client generally uses encryption to ensure data security when making network requests. After iOS9, Apple uses Https to protect data security. 2. What happens if the network is poor when a large number of images are loaded? What should I do? Data requests may be slow and Images cannot be loaded. Otherwise, the program crashes. Solution: 1. prepare the data cache. The program reads data from the cache first when using it. If the corresponding cache does not exist, it then requests data. 2. Control the number of requests and Data Volume 3. What network request methods have you used? What are the differences between third-party frameworks used? The http://m.blog.csdn.net/blog/quanqinayng/22325195 http Protocol declares the way the client interacts with the server, that is, the request method: get, post, put, delete the four methods can be on the network resources (url description content: query, modify, add, and delete CLLocationManager to locate and query and display the surrounding merchants in real time. two common methods are as follows: 1. get method: downlink/obtain data from the server (1) generally, get requests only obtain data from the server. When a request is made, some server request parameters are generally submitted, which are appended to the url and separated. (2) The url is recognized in Chinese, English, and numbers, while Chinese or some other characters need to be encoded. (3) the data submitted by the get request is generally placed in the header of the http protocol 2: post method: Upload/upload data changes the content of the server (1) post requests are mostly used to submit data to the server. (2) data submitted by post requests is generally stored in the http body of the main data packet. There are three types of Third-sending frameworks: ASIHttpRequest, AFNetWorking, and MKNetWork. three differences: ASIHttpRequest is bloated, and MKNetWork and AFNektwork are lightweight. I recommend MKNetWork, which is relatively simple. internal download and offline download Implementation of the APP (which can be downloaded offline like thunder): 1. create an NSURLSession and create an NSURLRequest2. accept data in the proxy and write data to the folder according to the path

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.