Differences between TCP and UDP

TCP UDP
Connection-oriented or not connection-oriented Connectionless oriented
Transmission reliability Reliable transmission Deliver as much as you can
Transfer form Byte stream Data packet segment
Transmission efficiency slow fast
The resources needed more less
The first byte 20-60 8

How does TCP implement reliable transmission

To summarize:

  1. Application data is divided into data blocks that TCP considers best for sending
  2. TCP USESThe serial numberandConfirm answer numberEnsure the sequential transmission of data.
  3. Checksum: The checksum of the TCP header verifies its header and data. If the packet segment changes during transmission or the checksum is incorrect, TCP dismisses the packet segment and does not acknowledge receiving the packet segment.
  4. The TCP receiver discards the packetrepeatThe data.
  5. Flow control:The sliding windowTo implement traffic control, the receiver can set the window size acceptable to itself in the packet to control the window size of the sender, so that the data sent by the sender can be accepted by the receiver in time.
  6. Congestion control: When the network is congested,Reduce excessive dataInject into the network.
  7. ARQ protocol: It also aims to achieve reliable transmission. Its basic principle is to stop sending each packet and wait for the confirmation of the other party. Send the next packet after receiving confirmation.

HTTP long and short links

Short connections: HTTP/1.0 uses short connections. After each HTTP operation, the CS closes the connection at the end of the task. Re-open a new connection when needed.

Long connections: HTTP/1.1 uses long connections. When the web page is opened, the TCP connection will not be closed after CS establishes a connection. When accessing the server again, the TCP connection that has been established can be used.

When to use long connections?

Long connection for more frequent operation, point-to-point communication, and the number of connections cannot too much, every TCP connection needs three steps to shake hands, it will take time, if every operation is the first connection, operation again processing speed will reduce a lot, so every operation after continuously open, every time processing directly to send packets with respect to OK, You do not need to establish a TCP connection. For example, if the database is connected to a long connection, frequent communication with a short connection will cause socket errors, and frequent socket creation is also a waste of resources.

What uses the short link?

And like the WEB site of the HTTP service with short links, as long it takes a certain connection to the server resources, and as frequently as the WEB site of thousands or even hundreds of millions of client connection with short connection will be more save some resources, if with long connection, and hundreds of thousands of users at the same time, if each user to take up a connection, Imagine that. So the concurrency is large, but each user does not need to operate frequently in the case of a short connection.

Difference between HTTP and HTTPS

  1. Port: The HTTP URL starts with http:// and uses port 80 by default, while the HTTPS URL starts with https:// and uses port 443 by default.

  2. Security and resource consumption: HTTP runs on TOP of TCP. All content transmitted is in plain text, and neither the client nor the server can verify the identity of the other. HTTPS is the HTTP protocol that runs on top of SSL/TLS, which runs on top of TCP. All transmitted content is encrypted using symmetric encryption, but the symmetric encryption key is asymmetrically encrypted using the certificate of the server. Therefore, HTTP is not as secure as HTTPS, but HTTPS consumes more server resources than HTTP.

    • Symmetric encryption: Only one key is used to encrypt and decrypt the same password, and the encryption and decryption speed is fast. Typical symmetric encryption algorithms include DES and AES.
    • Asymmetric encryption: The key is in pairs (and the private key cannot be deduced from the public key, nor the public key from the private key). Different keys are used for encryption and decryption (public key encryption requires private key decryption, and private key encryption requires public key decryption). Asymmetric encryption is slower than symmetric encryption.