Basic concept

  • The network is divided from bottom to top into the physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer (OSI). Through a preliminary understanding, I know that IP protocol corresponds to the network layer, TCP protocol corresponds to the transport layer, and HTTP protocol corresponds to the application layer. The three are essentially comparable, and socket is the encapsulation and application of TCP/IP protocol (programmer level). In other words, TPC/IP is a transport-layer protocol that deals with how data is transferred over the network, while HTTP is an application-layer protocol that deals with how data is packaged.

  • The network has an easy to understand introduction to TCP/IP and HTTP: “We could just use [transport layer] TCP/IP when transferring data, but then without the application layer, the content of the data would not be recognized. Application layer protocols must be used if you want to make sense of the data being transferred. There are many application-layer protocols, such as HTTP, FTP, and TELNET. You can also define application-layer protocols. The WEB uses HTTP as an application-layer protocol to encapsulate HTTP text, and then uses TCP/IP as a transport-layer protocol to send it to the network.”

Here are some important concepts that are often encountered in written tests or interviews.

TCP connection and release

Three handshakes are required to connect

  • First handshake: The client sends a SYN packet (SYN = J) to the server and enters the SYN_SEND state.
  • Second handshake: After receiving a SYN packet, the server must acknowledge the client’s SYN(ACK = J +1) and send a SYN packet (ACK = K). In this case, the server enters the SYN_RECV state.
  • Third handshake: After receiving the SYN+ACK packet from the server, the client sends an ACK packet (ACK = K +1) to the server. After the packet is sent, the client and the server enter the ESTABLISHED state to complete the three-way handshake.

The packet transmitted during the handshake does not contain data. After three handshakes, the client and server start data transmission. Ideally, once a TCP connection is established, it is maintained until either of the communicating parties voluntarily closes the connection. Both the server and client can initiate a request to disconnect the TCP connection. The disconnection process requires a four-way handshake.

Two, the use of Socket to establish network connection steps

Establishing a Socket connection requires at least one pair of sockets, one of which runs on the client, called ClientSocket, and the other on the server, called ServerSocket. The connection process between sockets is divided into three steps: server listening, client request, and connection confirmation.

  • 1. Server monitoring: the server socket does not locate the specific client socket, but is in the state of waiting for the connection, monitoring the network status in real time, waiting for the connection request of the client.
  • 2. Client request: the client socket makes a connection request, and the target connection is the server socket. To do this, the client-side socket must first describe the socket of the server to which it is connecting, specifying the address and port number of the server-side socket, and then make a connection request to the server-side socket.
  • 3, connection confirmation: when the server socket listens to or receives the connection request of the client socket, it responds to the request of the client socket, establishes a new thread, and sends the description of the server socket to the client. Once the client confirms the description, the two sides formally establish a connection. The server socket continues to listen, receiving connection requests from other client sockets.
Third, the characteristics of HTTP links

HTTP, also known as Hypertext Transfer Protocol, is the foundation of Web networking and one of the protocols commonly used in mobile networking. HTTP is an application based on TCP. The most remarkable feature of HTTP connections is that each request sent by the client requires a response from the server, and when the request is complete, the connection is released. The process from establishing a connection to closing a connection is called one connection.

The difference between HTTP and HTTPS
  • For HTTPS, you need to apply for a certificate from a CA. Generally, a free certificate is rare and requires a fee.
  • HTTP is a hypertext transmission protocol, and information is transmitted in plain text. HTTPS is a secure SSL encryption transmission protocol.
  • HTTP and HTTPS use completely different connections and use different ports, the former 80 and the latter 443.
  • HTTP connections are simple and stateless; HTTPS is a network protocol that uses SSL and HTTP to encrypt transmission and authenticate identity. It is more secure than HTTP.
5, TCP and UDP differences
  • 1, TCP is link-oriented, although the insecure and unstable characteristics of the network determines how many times the handshake can not ensure the reliability of the connection, but TCP three handshake in the minimum (in fact, also to a large extent to ensure) to ensure the reliability of the connection; UDP is not connection-oriented. It does not establish a connection with the other party before transmitting data, and does not send an acknowledgement signal to the received data. The sender does not know whether the data will be correctly received and does not need to resend.
  • 2. Because of the features mentioned in 1, UDP has a lower overhead and a higher data transmission rate. Because there is no need to confirm the sending and receiving data, UDP has a better real-time performance. Knowing the difference between TCP and UDP, it is not difficult to understand why MSN using TCP transmission protocol is slower than QQ using UDP, but it can not be said that QQ communication is not secure, because programmers can manually verify the UDP data sent and received. For example, the sender numbers each packet and then the receiver verifies it. Even so, UDP achieves the transmission efficiency that TCP cannot achieve because it does not adopt the “three-way handshake” similar to TCP in the encapsulation of the underlying protocol.
TCP/IP Layer 4 protocol

1) Network interface layer: this layer mainly involves some physical transmission, such as Ethernet and wireless LAN. 2) Network layer: provides hardware independent logical addressing to realize the conversion of physical address to logical address. In the TCP/IP protocol family, network layer protocols include IP (Internet Protocol), ICMP (Internet Control Message Protocol), And THE IGMP protocol (Internet Group Management Protocol) is currently the most used in the market is 32-bit binary IPv4, because IPv4 addresses are not enough. So 128-bit binary IPv6 is becoming more and more popular (but this is all based on IPv4)

  • IP: Each network adapter on a TCP/IP network has a unique IP address. The IP address is a 32-bit address, which is usually divided into four bits. Each bit is divided into eight bits. However, each bit is converted to decimal for easy reading. Network ID && Host ID Most IP addresses belong to the following types of Class A addresses: The first eight bits of an IP address represent network ids, and the last 24 bits represent host ids. Class B address: The first 16 bits of an IP address represent the network ID and the last 16 bits represent the host ID. Class C ADDRESS: The first 24 bits of an IP address represent the network ID and the last 8 bits represent the host ID. It is obvious that A class A address can provide fewer network ids, but each network can have many hosts. If A 32-bit IP address starts with 0, it is A Class A address. If a 32-bit IP address starts with 10, it is a class B address. If a 32-bit IP address starts with 110, it is a class C address. In decimal notation, we can use the decimal number in the first paragraph to distinguish what kind of IP address is.
  • Address resolution protocol ARP in simple terms, ARP maps IP addresses to physical addresses, while RARP maps physical addresses to IP addresses.
  • The classification of IP addresses mentioned above, but for class A and CLASS B addresses, the number of hosts under each network is too large, so network transmission becomes inefficient and inflexible. For example, the class A IP address is 100.0.0.0. There are more than 16 million hosts in this network. So subnet masks were invented to solve this problem. Let’s review how we distinguished host IP from network IP. Take class A address 99.10.10.10 as an example. The first eight bits are network IP addresses, and the last 24 bits are host IP addresses. (As shown below)

    The subnet mask is also a 32-bit binary number, or can be divided into four decimal numbers. Each bit of the subnet mask corresponds to the corresponding position of the IP address. The value 1 indicates the non-host bit, and the value 0 indicates the host bit.

It can be clearly seen from the table that the number of bits of network IP is still determined by the previous classification, while the number of bits of host IP is determined by the number of bits whose subnet mask value is 0, and the rest are subnet IP

    1. Transport layer: Provides traffic control, error control and validation services for the network. There are two distinct transport protocols in the TCP/IP protocol family: TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). These are two ways to reach the target network: Transmission Control Protocol (TCP) is a connection-oriented protocol that provides complete error control and traffic control to ensure the normal transmission of data. User Datagram Protocol (UDP) : provides only basic error detection and is a connectionless protocol. Features:

UDP: the data is packaged with a limited data size (64 KB). The connection speed is fast but the reliability is low. TCP: the connection channel is established with an unlimited data size

    1. Application layer: for network troubleshooting, file transfer, remote control and Internet operation to provide specific applications application layer as the highest level of TCP/IP protocol, for our mobile development, is the most contact.

Protocol running over TCP: Hypertext Transfer Protocol (HTTP), used for common browsing. Hypertext Transfer Protocol over Secure Socket Layer (HTTPS), a Secure version of HTTP. File Transfer Protocol (FTP) is used for File Transfer. POP3 (Post Office Protocol, Version 3) is used to receive mails. SMTP (Simple Mail Transfer Protocol) is used to send emails. TELNET (Teletype over the Network) is a method of logging in to the Network through a terminal. Secure Shell (SSH) is used to encrypt and Secure login.

Protocol running on UDP: Boot Protocol (BOOTP), applicable to diskless devices. Network Time Protocol (NTP) is used for Network synchronization. Dynamic Host Configuration Protocol (DHCP) is used to dynamically configure IP addresses. Others: The Domain Name Service (DNS) is used to search IP addresses and forward mails (running over TCP and UDP). ECHO (ECHO Protocol), used to check errors and measure response time (running over TCP and UDP). Simple Network Management Protocol (SNMP) is used to collect Network information and manage networks. Address Resolution Protocol (ARP) is used to dynamically resolve Ethernet hardware addresses.

##### 7. TCP/IP Packet In TCP/IP protocol, data is packed from top to bottom and then unpacked from bottom to top. During packet loading, information is added to each layer for transmission, which is called headers. So let’s keep going.


Welcome to pay attention to my public number