Preface:

Between their own network knowledge rotten in a complete mess, so ready to write the relevant network article, but consider all written in one is too long, so separate write, I hope you can look carefully, the best can point out my mistakes, let me also can correct.

1. Explain the whole network architecture:

Android Skill Tree – Network Summary (1) network Architecture

TCP, UDP,socket,websocket, HTTP, HTTPS. What is webService? It is similar to websocket. Socket and Websocket are similar in terms of session,token and cookie.

Android Skill Tree – Network Summary (2) TCP/UDP

Android Skill Tree – Web Summary (3) HTTP/HTTPS

Android skill tree – network summary (4) of the socket/websocket/webservice

Cookie /session/token (to be written)

3. Source code analysis of relevant third party frameworks, after all, okHTTP and Retrofit source code is a must for interviewing large companies now.

Android Skill Tree – Network summary (6) OkHttp super super super super super super super super super super detail analysis

Android Skill Tree – Network Summary (7) Retrofit source code detailed parsing

Network knowledge is actually a lot of development estimates are very weak, many development has been using some framework, and then the background agreed to return the data structure, and then can work. For example, once we know the API for a retrofit call and fill in the relevant HTTP URL and the specified parameters to be passed to the server, we can get the relevant return JSON:

{
    "success":true."msg":"xxxx"."data": {"key1":value1,
        "key2":value2}} (' 'code' 'is used to return the value of' 'success', and then mobile to determine if it is 200.)Copy the code

We can then use FastJson or Gson to convert it into an object and use it in our app.

So a lot of times, we find that we don’t know anything about the web and we can still make an app. And it is also reasonable, but once you go to the interview with a larger company, ask a little more detailed, you will be directly speechless, and then basically the interview GG.

Because my network foundation is also super poor, so THIS time I refer to other people's articles, understand by myself, and make a summary. Relevant links will be attached at the end of the article, and some pictures are also directly referred to the pictures in the articles of these bigshots. (So don't spray me directly steal pictures).

1. Network architecture

I don’t know if you ever wrote a letter and sent it through the post as a kid, but back then you had to manually write it on a piece of paper and stuff it in an envelope, and then write on the envelope the sender’s information, the recipient’s information, the zip code, etc., and then you could mail it to your destination. And the recipient is most concerned about the real contents of the paper, even without looking at the envelope information.

When we send the relevant information, it’s a bit like sending a letter. We just write the relevant main message, but it can be sent to the designated location, because it encapsulates the data layer by layer (kind of like helping to write the message on the envelope). Then, when they receive the message, they only see the main message we sent them (kind of like opening the envelope and taking out the main content).

If you look at this picture, it feels a lot like sending a letter, where our main DATA content is wrapped layer by layer, and then unwrapped layer by layer when it gets to the recipient.

Now, some of you might ask, well, what exactly is going on in these layers, but let’s imagine now that you know something about them, like their address and your address; All kinds of agreed agreements (like the zip code on our envelopes); For example, if you write in English or In Chinese, the other party should also be able to understand it. It is better to agree with each other so that the other party can understand it better after sending the letter.

Let’s look at it step by step:

1.1 OSI architecture

In fact, the diagram above uses the OSI architecture, so we can see that there are seven layers.

Excuse me… Wrong set… It should be the picture below.

In fact, look at the picture above has a general idea:

  1. Physical layer: Defines physical device standards, such as the interface types of network cables, optical fibers, and transmission rates of various transmission media. The main function is to encode data into a bit stream identified by 0 and 1, which is transmitted through physical media. This layer of data is called bit.
  2. Data link layer: Encapsulates and decapsulates the MAC address (nic address) of the received data. This layer of data is often called a frame. The devices that work in this layer are switches.
  3. Network layer: encapsulates and decapsulates IP addresses of received data. This layer of data is often referred to as a packet. This layer of devices is the router.
  4. Transport layer: defines some data transfer protocols and port numbers. The received data is segmented and transmitted, and then reassembled after arriving at the destination address. This layer of data is often referred to as a segment.
  5. Session layer: Establishes the data transmission path through the transport layer. Initiate or receive session requests between systems.
  6. Presentation layer: mainly interprets, encrypts, decrypts, compresses and decompresses the received data. Ensure that data sent by the application layer of one system can be identified by the application layer of another system.
  7. Application layer: Mainly provides services for some terminal applications. Directly to the user.

Here’s a more concrete picture:

Then many people say that seven layers are too many to understand, and then they give up directly. (PS: I also give up myself) Although I know that it encapsulates a lot of things, there are too many layers, and I really don’t want to see it. So later we see other structures with fewer layers

1.2 TCP/IP Architecture

The TCP/IP architecture simplifies the computer network structure from seven layers to four layers, but it does not reduce its functionality.

Isn’t it a lot less all of a sudden, we know that one piece of data goes from one place to another, it’s a lot like sending a letter, so let’s just send a letter to make it easier to understand. There are only a few conditions for sending a letter:

  1. You have to have a mailbox to mail your letter, and then you drop it in and they take it.
  2. To know each other in which city (that is, you fill in the zip code number), or you don’t know this letter is sent to which city, perhaps even to transfer several times, you send a letter to a city, sometimes some near cities can direct, sometimes some distant city is to transfer a number of cities, and finally to reach the destination)
  3. The letter was delivered to the post office of the city, but accompanied by many other letters to the city, at this time to a specific street in the city, a community and so on. At this time will be based on their envelope above the specific recipient information to determine the letter is to a specific person.
  4. When the letter arrives at the recipient, the envelope may be written in English or Chinese, or it may be an encrypted letter composed of a certain format, so the recipient needs to ask relevant people to translate and explain the letter in order to understand it. (Anyway, I must find someone who is good at English to translate for me.)

TCP/IP layer 4 protocol TCP/IP layer 4 protocol TCP/IP layer 4 protocol

  1. Network interface layer: Just like the mailbox, we definitely need to have the corresponding physical layer (such as network related hardware), and also put some core information, such as IP, etc. (so that the post office knows which city transport truck to put your letter in).
  2. The network layer: We know about IP, which is to transfer data from one host to another, possibly with a relay in between(Similar to sending a letter from one city to another). Details can be seen:Role of the network layer
  3. Transport layer: A computer may have more than one process using network connection at the same time, so after the network packet reaches the host, how to distinguish which process it belongs to?(A lot of letters arrive in the city, but who does yours belong to?)Therefore, after receiving data from the network layer, the transport layer must deliver the data correctly to an application, that is, the transport layer can distinguish and process data from different processes.(Conversely, when on the sender side, the transport layer receives the packet from the application and encapsulates it in the transport layer segment before sending it to the network layer.). For details, please refer to:Overview of transport layer functions
  4. Application layer: This layer includes all the protocols that work with applications to exchange application-specific data using the underlying network. The application layer is the layer that most common network-related programs use to communicate with other programs over the network. The processing of this layer is application-specific; Data is transmitted from network-related programs in this format for internal use in the application, and then encoded into a standard protocol format. Commonly used procedures such as E-mail reception (POP3), remote login (TELNET), file transfer access (FTP), domain name resolution service (DNS), control letters sent and transferred (SMTP), etc. (is not equivalent to we received an English letter please good English translation, received encrypted letters, please crack master to help translate)

1.3 TCP/IP five-tier architecture

In fact, it is similar to the above four layers, except that the bottom network interface layer is split into the OSI’s bottom two layers: the physical layer and the data link layer. Everything else is the same.

1.4 Corresponding relationship of respective systems

Look at the picture is not immediately understand the relationship between the three, similar to TCP/IP structure is more OSI seven layer standard, the combination of several layers into a simple layer. To understand it better.

conclusion

emmmm……… I want you to spray lightly.

Reference article:

Overview of transport layer functions

Role of the network layer

One of the basics of network: a detailed explanation of network architecture

Network Model (7-layer network model)

Talk about the past life of Android network communication — network foundation

This is a detailed and clear study guide for the basics of computer networking