TCP-IP Protocol [Advanced Programming Learning]

  • Recommended book "Graphic TCP/IP"

1. What happened after entering the url address?

1. url (uniform resource locator)

  • composition:

protocol://domain name[:port]/path
eg: https://www.baidu.com/
file:///H:/BaiduNetdiskDownload/

  • Role: Locate the specified resource.

url is a subset of uri, uri is the meaning of unique identifier. ID card can be uri, but not url.

2. DNS resolution

  • Domain Name System Domain Name System, which resolves domain names into IPaddresses

  • Domain name resolution process

    Domain name (www.baidu.com) -> DNSserver -> return the real IPaddress 36.152.44.96:443-> IPaccess the server through the address

  • The client establishes a connection with the server.

The client and the server must confirm each other's identities, and then send data after establishing a connection channel

  • The client formally sends a request to the server.

  • The server processes the request and returns the result

  • After the browser receives the response, it renders accordingly

3. TCP/IP five-layer protocol

insert image description here
The corresponding relationship between the TCP/IP five-layer protocol and the OSI seven-layer protocol is as follows.
insert image description here
Different devices work at each layer. For example, our commonly used switches work at the data link layer, and general routers work at the network layer.
insert image description here
The protocols implemented at each layer are also different, that is, the services of each layer are also different. The following figure lists the main protocols of each layer.
insert image description here

  • application layer

    • Provide services between processes (client applications) and processes (server applications). The application layer protocol defines the way of data interaction between applications.

      For example: browsing the web Netease Cloud uses python to simulate requests

  • transport layer

    • Responsible for providing services for communication between two host application processes.

      A host can open different client applications and communicate with different servers, but they all share a transmission service to send and receive information
      Process <—> Process
      Transport layer protocol

    • TCP (Transmission Control Protocol)

      Provide connection-oriented, (as much as possible) reliable data transmission services. Connection-oriented means that the client and the server perform three interactive verifications, that is, the TCP three-way handshake. Data can only be sent after the connection is established.

      • File Transfer (FTP)
      • Browse the web (HTTP)
    • UDP (User Data Protocol)

      Provides connectionless, does not guarantee the reliability of data transmission

      One-to-many, one-to-one, many-to-many... such as: live broadcast, live games

  • Network layer

    • It determines the forwarding and path selection of data , the packet/user data segment generated by the encapsulation and packet transport layer. host <—> host

    • Network layer protocol:

      • IP protocol:
        Public IP: refers to the traditional IP address, which is unique.
        Local IP:

        View: command character –> ipconfig

  • data link layer

    • Responsible for data transmission between two hosts, and provide data transmission services to the network layer. NIC<—> NIC

    • The role of the data link layer

        比特流在传输媒介上传输时肯定有误差, 数据链路层的作用就是检错和纠错
      
      • *flow control
      • error detection
      • error control
  • physical layer

    The physical layer transmits data frames on the local area network, and transmits bit streams at the device nodes. Optical fiber <—> optical fiber
    ps: physical layer and data link layer: the physical layer is what actually transmits data, and the data link layer is used to check data integrity.

2. Understand the TCP/IP protocol

1. Concept

  • What is TCP/IP Protocol

    TCP/IPIt is not a single protocol, but a set of protocols, so it is TCP/IPalso called TCP/IPa protocol family.

  • The role of TCP/IP

    It acts as a link between the application and the hardware.

    手机的APP应用 -> 路由器 -> 光猫 -> 运营商网络 -> 互联网
    

2. TCP/IP three-way handshake

In order to establish a reliable TCPconnection, ensure the correctness of data transmission as much as possible.
insert image description here

  • The three-way handshake process

    • The client sends a data packet with a logo to the server SYN(同步序列编号)--------------------------- The server confirms that the sending ability of the client is normal
    • The server sent SYN-ACK(确认字符)a data packet with a logo to the client ----------------------- The server confirmed that its ability to accept is normal
    • ACKThe client returns a packet with an identifier to the server ------------------------------------ ---------The server confirms its sending capability, and the client accepts it normally
  • The second handshake has been sent back ACK, why does the server return SYN?

    In order to tell the client that the signal received is indeed the signal it sent, indicating that the communication from the client to the server is normal.

3. TCP/IP waves four times

insert image description here

我们以客户端作为主动关闭方来描述四次挥手过程
  • The client sent a FIN(finish)packet to the server --------------------------------------Close the client Connection channel to the server
  • After the server receives it FIN, it returns ACKthe data packet ----------------------------------------- ------------The server already knows that the connection channel from the client to the server is closed
  • The server sends FINa data packet to the client, closes the connection with the client ------------------------------ The purpose is to close the server to client connection channel
  • Client returns ACKpacket confirmation -------------------------------------------- ------------------- Notify the server that the client has already known that the connection channel between the server and the client has been closed

3. HTTPS

insert image description here

  • https encryption process

    • The client sends a communication request to the server

    • The server returns the certificate and key to the client

    • The client verifies the authenticity of the certificate through the CA center

    • After the client completes the authentication, it encrypts the sent data with the public key and sends it to the server.

    • asymmetric encryption

      16 = 2* 8 也可以是 4 * 4
      公钥就是拿到了16这个结果
      私钥就是某个因数2
      通过这样的方式才可以得出唯一解8
      
    • After receiving the encrypted request data, the server uses the private key to decrypt it.

    • Server and client communicate using symmetric encryption

  • man-in-the-middle attack

    Inserted into the communication between the client and the server, it is safe for the server to forge the client, for the client to forge the server, and intercept the data generated by the communication.

    • The resulting conditions
      Our client must actively trust the certificate of the intermediary

Guess you like

Origin blog.csdn.net/weixin_52312427/article/details/129130965