Computer network foundation for Android interview

Foreword : Start to summarize an interview information of your own. Although it is available online, collecting and browsing is really not as good as understanding and absorbing. Come on,

1. The structure and function of each layer, and what protocols are there

The OSI system structure has 7 layers, and here we talk about 5 layers according to the TCP/IP system structure.

Physical layer >>> data link layer >>> network layer >>> transport layer >>> application layer (presentation layer, session layer)



1.1, application layer

Application layer tasks: through the communication interaction between application processes to complete a specific network application

application layer protocol: communication interaction rules between application processes

message: the data unit of application layer interaction

supports the following protocols:

  • Domain Name System (DNS)
  • World Wide Web HTTP Protocol (HyperText Transfer Protocol)
  • SMTP protocol for email

Domain Name System DNS: A distributed database that maps domain names and IP addresses to each other, which is convenient for users to access quickly. For example, github, if you visit in Japan, you are accessing the server in Japan, and the server in China is the Chinese server. So he is a distributed.
The role of the domain name protocol: convert the domain name into an IP address to find the corresponding host

HTTP protocol: Hypertext Transfer Protocol, WWW (World Wide Web) all comply with this protocol. The original purpose was to publish and receive HTML pages.


Application layer vernacular :
here can be understood as the translation process between computers, binary encoding of data



1.2. Transport layer

Transport layer tasks: Provide general data transmission services for communication between two host processes.

Transport layer protocol: Transport layer data transmission service rules The

transport layer has multiplexing and

demultiplexing functions; multiplexing: One host can open multiple threads, Multiple application processes can use transmission service

sharing at the same time : the transmission layer receives the message, and delivers it to the correct Socket according to the header information of the message, that is, to the corresponding application process

The supported protocols are:

  • TCP (Transmission Control Protocol) >>> Transmission Control Protocol; connection-oriented, providing reliable data transmission services
  • UDP (User Datagram Protocol) >>> user data protocol; for connectionless, does not guarantee the reliability of data transmission
    (TCP and UDP will be described in detail later)

Transport layer vernacular : The
transport layer divides the upper layer data into many data segments to facilitate error resolution, and encapsulates each segment of data with a port number in the header



1.3, network layer

Network layer tasks: select appropriate routing and switching nodes between networks to achieve communication between terminal nodes.

Network layer protocol: Protocols

supported by network layer transmission rules :

  • IP protocol >>> encapsulate the messages and user data generated by the transport layer into combined data packets for transmission
  • ARP Protocol >>> Address Resolution Protocol
  • RARP Protocol >>> Reverse Address Resolution Protocol

Network layer vernacular : The
network layer re-encapsulates the upper layer data into an IP datagram, with an IP address in the header, which is used to identify the network logical address



1.4, data link layer

Data link layer: Encapsulate data into data frames, and then transmit

frames on each link. Lost frames: The control information of the data link layer can detect errors in the data frame at the receiving end. If there is an error, discard the frame to avoid Continue to transmit wastes resources. If data needs to be corrected, a reliable transmission protocol must be used to correct errors. (This shows that the data link layer can not only detect errors but also correct errors)


The data link layer vernacular : the
data link layer re-encapsulates the uploaded data into a data frame, and its MAC header contains an important MAC address information. Can be understood as the physical address solidified in the hardware



1.5, physical layer

Physical layer: to achieve transparent transmission of bit streams between adjacent computer nodes


The vernacular of the physical layer :
convert upper-layer data into electrical signals for transmission on the network


1.6, supplementary points

Correspondence between common hardware devices and the five-layer model.
Application layer: computer (in fact, the computer is integrated with OSI seven layers).
Transmission layer: firewall.
Network layer: router (strictly speaking, it is inconsistent with the home router used in our house. Generally speaking, it can be in the computer room. See)
Data link layer: switch (such as the optical
modem at home) Physical layer: network card



2. TCP three-way handshake and four waved hands

Simple diagram of TCP three-way handshake:

2.1. Why is there a three-way handshake?

The client sends a SYN (handshake signal established by TCP/IP) --> the server sends a SYN/ACK message to the client after receiving it. The response indicates that it has been received --> the client sends an ACK to the server to indicate that it has been received.

SYN: indicates that the message from the client to the server is correct

ACK: indicates that the message from the server to the client is correct


Example: Normal relationship between boy and girl friends. The client (girlfriend) sends the message "I am going to sleep" --> the server (boyfriend) receives the message and sends "Good night". If the client (girlfriend) does not respond at this time, it means that this is an abnormal relationship between men and women. If the client (girlfriend) sends "Ann" at this time, it means that the relationship between the two parties is normal and that you are worth marrying home. This is why there are three handshake! ! !

Simple schematic diagram of TCP waving four times:

2.2. Why wave four times

Any party can send a connection release notification when there is no message to send. Note that the TCP connection is not completely closed at this time. After the other party confirms, it enters the half-closed state. When the other party has no message to send, the connection release notification is also sent, and then the TCP connection is completely closed.


Example: A and B make a phone call. When the call is about to end, A says "I have nothing to say", B answers "I know", but B may still have something to say, A cannot ask B to follow his own Rhythm ends the call, so B may say another word to Barabara, and finally B says "I'm finished", and A answers "I know", so the call is over.



Third, the difference between TCP and UDP protocols

UDP: For connectionless, fast speed. Unreliable

TCP: The connection is established before the data is transmitted, and the resources are released after the data transmission is over. Reliable but relatively slow transmission rate.

The reliability of TCP is embodied in: establishing a connection before transmitting data, and ensuring the reliability of data transmission through confirmation, window, retransmission, and congestion mechanisms during data transmission.



Fourth, enter the URL address in the rover >> the process of displaying the homepage

1. DNS analysis, find the corresponding ip address

2. Establish TCP connection

3. Send HTTP request

4. Server process and return HTTP message

5. Vagrant resolves and renders the page

6. Connection ends



Five, status code summary



Six, HTTP short connection and long connection

Short connection: A connection is established every time a network request is made, and the connection

is interrupted. Long connection: After the network request is over, the connection will not be interrupted immediately, nor will the connection be permanently maintained, but within a set time, when there is no transmission disconnect.

//使用长连接,会在响应头加入这行代码
Connection:keep-alive


7. What is the role of cookies? What is the difference with Session

Cookie and Session are both session methods used to track the identity of the rover user, but the user scenarios of the two are different.

  • Cookie: Data is saved on the client. Do not write some sensitive data, and it is best to get the server to decrypt it after encryption
  • Session: Data is stored on the server


8. What is the difference between URI and URL

URI (Uniform Resource Identifier): is the same resource identifier, which can uniquely identify a resource

URL (Uniform Resource Location): is the same resource locator, which can provide the path of the resource. It is a specific URI, which is a subclass of URI.



Nine, the difference between HTTP and HTTPS

HTTP: Hypertext Transfer Protocol. The URL starts with "http" and the port number defaults to 80. The transmission is completely plain text without encryption, and the security is low.

HTTPS: HTTP running on SSL/TLS has high security. The URL starts with "https" and the port number defaults to 443.


Symmetric encryption : There is only one key, and the encryption and decryption are the same password, and the encryption speed is fast. Insecure: If the middleman intercepts the key from the beginning of the communication, the information will be leaked.

Asymmetric encryption : There are two public keys, and different keys are used for encryption and decryption. For example, Xiao Ming has key A and public key B. Send public key B to Xiaohong, Xiaohong uses public key B to encrypt her own public key C, and sends it to Xiaoming. Xiaoming uses his own key A to decrypt his public key B to obtain Xiaohong's public key C. Later, Xiaoming sends messages to Xiaohong encrypted with Xiaohong's public key c, and Xiaohong sends messages to Xiaoming encrypted with Xiaoming's public key B. This is relatively safe. In fact, it is not absolutely safe: if the intermediary intercepts the public key B as soon as it is opened, replaces it with its own public key, and sends it to Xiaohong, the information can also be intercepted.

SSL/TLS : Different from asymmetric encryption, it is done through the certificate authority on the rover or operating system. The rough meaning is to use the public key of the vagrant and the certificate authority to encrypt and generate a signature. After the receiving end receives it, use the agreed public key to generate a signature and compare the signature of the received information. After it is correct, confirm that it has not been hijacked by an intermediary, then decrypt the information and encrypt the transmission information



References (thanks)

Basic knowledge of

computer network Data transmission process of

computer network

What is HTTPS protocol?

Guess you like

Origin blog.csdn.net/leol_2/article/details/105262409