Android network programming (1) network layering and protocol introduction

1 Overview

OSI / RM

In 1978, the International Organization for Standardization (ISO) proposed the "Open System Interconnection Reference Model", the well-known OSI / RM model (Open System Interconnection / Reference Model). Since then, computers from different manufacturers can communicate with each other and establish a computer network. OSI / RM divides the communication protocol of computer network architecture into seven layers, from bottom to top: physical layer, data link layer, network layer, transmission layer, session layer, presentation layer, application layer.

TCP/IP

Because the OSI / RM model is too complicated and difficult to implement, the TCP / IP model is widely used in reality. It is a network architecture and protocol specification introduced by ARPA from 1977 to 1979. TCP / IP is a set of protocols, not referring to TCP and IP. In many cases, it is a general term for the protocol group that must be used when communicating with IP. Specifically, IP or ICMP, TCP or UDP, TELNET or FTP, and HTTP are all TCP / IP protocols. Their close relationship with TCP or IP is an essential part of the Internet. The term TCP / IP refers to these protocols in general, so TCP / IP is sometimes called the Internet Protocol Group. When communicating on the Internet, the corresponding network protocol is required. TCP / IP was originally a protocol family developed for the use of the Internet. Therefore, the Internet protocol is TCP / IP, and TCP / IP is the Internet protocol.

The TCP / IP model is also a layered model, divided into 4 layers. The reference hierarchy of OSI / RM model and TCP / IP model is shown in the figure:

Application layer : It is the layer used by most common network-related programs to communicate with other programs through the network. In the application layer, data is transmitted in the format used internally by the application, and then encoded into a standard protocol format. Such as HTTP protocol, FTP protocol, POP3 and IMAP protocol for receiving e-mail, SMTP protocol for sending mail, and SSH and Telnet for remote login. So users usually interact with the application layer.

Transport layer : Provides transparent data transmission between two hosts. It is usually used for end-to-end connection, flow control or error recovery. The two most important protocols at this layer are TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).

Network layer : Provides end-to-end packet delivery. It is responsible for sending packets from source to destination. Tasks include network routing, error control, and IP addressing. The important protocols included in this layer are IP (version 4 and version 6), ICMP (Internet Control Message Protocol, Internet Control Message Protocol) and IPSec (Internet Protocol Security, Internet Protocol Security).

Network interface layer : responsible for sending and receiving IP datagrams through the network; allowing hosts to use a variety of ready-made and popular technologies such as Ethernet, token network, frame relay, ATM, X.25, DDN, SDH, WDM, etc.

 

An application layer applications usually use two transporting layer one protocol: Connection-oriented TCP transmission control protocol and a connectionless UDP User Datagram Protocol . The following briefly introduces the HTTP, TCP, UDP, and IP protocols commonly used in the TCP / IP protocol stack.

2 HTTP protocol

HTTP (HyperText Transport Protocol) protocol is the most widely used network protocol standard on the Internet. It is an application layer protocol suitable for distributed hypermedia information systems. It was introduced in 1990 and is now widely used and continuously improved and expanded. HTTP is the result of the cooperation between the World Wide WebConsortium and the Internet Engineering Task Force. Its history is as follows:

HTTP 0.9 : The first version released in 1991, there is only one command GET, the server can only respond to HTML format strings.

HTTP 1.0 : The version released in 1996, the amount of content has greatly increased. In addition to GET commands, POST commands and HEAD commands are also introduced. In addition to the data part of the HTTP request and response format, each communication must include header information to describe some metadata.

HTTP 1.1 : The version released in 1997, which further improved the HTTP protocol, is still the most popular version until now. HTTP1.1 stipulates the use of long connection (Persistent Connection), so that multiple requests can be sent on the same TCP connection, making up for HTTP1.0 each request to re-create the connection leads to performance consumption and delay, and also proposed pipeline (Pipelining) to optimize the disadvantage of sending multiple requests on a single TCP connection without waiting for the corresponding response, although the server will still send the response in the order of the received requests.

SPDY : A protocol developed by Google in 2009 to solve the problem of low HTTP 1.1 efficiency.

HTTP 2 : The newly released version in 2015, the main features of the SPDY protocol are also in this version, Google also announced plans to remove support for SPDY, embrace HTTP / 2, and will take effect in Chrome 51. HTTP 2.0 proposes multiplexing (Multiplexing) to achieve multiple requests concurrently on a connection, avoiding the problem that multiple responses like HTTP1.1 may be blocked.

3 HTTPS protocol

HTTPS is to establish an SSL (Secure Sockets Layer) encryption layer on HTTP , and encrypt the transmitted data. It is a secure version of the HTTP protocol. HTTPS requests are safe, so there is no initial eavesdropping, tampering, or impersonation during the request process.

In a typical SSL usage scenario, a certificate is used to configure the server with a public key and a matching private key. Let the client also have one or more certificate sets that it trusts. If the requested URL address finds that the certificate is not in this set, the server will not be trusted and the request will fail.

The server is usually configured with certificates issued by a well-known issuer (called a certificate authority (CA)). The host platform generally contains a list of well-known CAs that it trusts. Starting with Android 4.2 (Jelly Bean), Android currently includes more than 100 CAs updated in each version. The CA has a certificate and a private key, which is similar to the server. When issuing certificates for the server, the CA uses its private key to sign the server certificate. The client can then verify that the server has a certificate issued by a CA known to the platform. The differences between
HTTPS and HTTP are: HTTPS is an encrypted transmission protocol, HTTP is a name-text transmission protocol; HTTPS requires an SSL certificate, but HTTP is not used; HTTPS standard port 443 , HTTP standard port 80, etc.

SSL/TLS

In fact, SSL is TLS. Here is a history:

In 1994, NetScape designed version 1.0 of the SSL protocol, but it was not released.

In 1995, NetScape released SSL version 2.0, and soon discovered that there were serious vulnerabilities.

In 1996, SSL version 3.0 came out and was widely used.

In 1999, the Internet Standardization Organization ISOC succeeded NetScape, and released the upgraded version TLS (Transport Layer Security) 1.0 of SSL.

In 2006 and 2008, TLS was upgraded twice, namely TLS version 1.1 and TLS version 1.2. The latest change is the 2011 revision of TLS 1.2.

At present, the most widely used is TLS 1.0, followed by SSL 3.0. However, mainstream browsers have already implemented TLS 1.2 support. TLS 1.0 is usually labeled SSL 3.1, TLS 1.1 is SSL 3.2, and TLS 1.2 is SSL 3.3.

4 TCP protocol

Transmission Control Protocol (TCP) is a connection-oriented, reliable, and transport layer communication protocol based on byte stream. Stream refers to an uninterrupted data structure. When the application uses TCP to send messages, although the order of sending can be guaranteed, it is still as if there is no interval of data stream sent to the receiving end. In order to provide reliable transmission, TCP can perform retransmission control when packets are lost, and it can also implement a sequential control mechanism for out-of-order packets. In addition, because TCP is a connection-oriented protocol, data is sent only when the peer of the communication is confirmed, and thus has many functions such as "flow control", "congestion control", and improved network utilization. The famous three-way handshake refers to the establishment of a TCP connection that requires the client and server to send a total of three packets to confirm the establishment of the connection, while the termination of the TCP connection is four waves, requiring the client and server to send a total of four packets to confirm Disconnection.

5 UDP protocol

User Datagram Protocol ( the User Datagram Protocol , UDP) is a TCP / IP model oriented connectionless transport layer protocol provides transaction-oriented messaging service simply unreliable. The UDP protocol is basically the interface between the IP protocol and the upper layer protocol. The UDP protocol is suitable for multiple applications with ports running on the same device. Unlike TCP, UDP does not provide a reliable mechanism for IP protocol, flow control, and error recovery functions. It does not need to establish a connection before data transmission. Because UDP is relatively simple, the UDP header contains very few bytes, so it consumes less than the TCP load. UDP is suitable for situations that do not require a reliable TCP mechanism, for example, when high-level protocols or applications provide error and flow control functions. UDP serves many well-known application layer protocols, including Network File System (NFS), Simple Network Management Protocol (SNMP), Domain Name System (DNS), and Simple File Transfer System (Trivial File Transfer Protocol, TFTP).

6 IP protocol

Internet Protocol (IP) is a data-oriented protocol used in message exchange networks. IP is the main protocol of the network layer in the TCP / IP protocol. The task is to transfer data according to the addresses of the source host and the destination host. To achieve this, IP defines the addressing method and datagram encapsulation structure. The main version of the first architecture, now known as IPv4, is still the most important Internet protocol. IPv6 is currently being actively deployed around the world.

 

Published 106 original articles · praised 37 · 80,000 views

Guess you like

Origin blog.csdn.net/lyz_zyx/article/details/96326534