Simple and detailed explanation of Http, Socket, Tcp

Simple and detailed explanation of Http, Socket, Tcp

Insert picture description here

Transport layer TCP, UDP, Socket
  • The TCP : for connection of reliable transmission.

    Connection : logical connection -> three-way handshake (I handshake three times to send data packets, after the three-way handshake, the kernels of both sides will open up resources in the memory and establish a connection) -> send intermediate data -> wave four times

  • Socket : socket (ip + port: ip + port), ip + port: ip + port constitutes the only connection. It is the basic operation unit of network communication supporting TCP/IP protocol. It is an abstract representation of endpoints in the process of network communication.

  • Transmission control layer : Provides reliable end-to-end network data flow services to the upper layers , that is, handshake packets/data packets.

  • Network layer : Through routing table addressing, I found the next hop ip address and knew the server ip and port I want to access

    Next hop: After the router receives any IP packet, it must find a matching route in the local routing table according to the destination IP carried in the IP packet, and then forward the IP packet to the next hop specified by the route. (Cmd: route print)

  • Link layer : Find the corresponding network card address (Mac) through the ip address of the next hop. Packet encapsulation server (ip + port) + Mac (next hop hardware address)

Insert picture description here

  • Physical layer : The physical layer is responsible for finally encoding data packets into current pulses or other signals for online transmission;
The relationship between Http, tcp, and Socket

TCP is a connection level of basic communication, and Socket encapsulates tcp and udp. The channel in Java wraps the socket, and the data flowing in and out of the channel can be restricted and identified through protocols, such as http, redis, and so on.

Interview question: If a client uses java to send http1.1 requests in a loop without disconnecting the tcp connection, what problems will it cause?

  • The client kernel cyclically applies to occupy the port, reaching the upper limit of 65535, and the client reports an error Address already in use: connect.
  • The number of TCP connections of the service reached the upper limit, causing the client to block the next request and time out.

Http1.1 uses keepalive by default to maintain a long connection, and requires the client to actively wave four times. The principle is that the application layer adds a flag to control whether the transmission control layer should wave four times.

Guess you like

Origin blog.csdn.net/weixin_44981707/article/details/111462419