This article is excerpted from kobayashi’s blog post

[toc]

1.1 the TCP/IP

Interprocess communication includes pipeline, message queue, shared memory, signal and other ways, which require network communication. In order to be compatible with different devices, a common network protocol is negotiated

The protocol is layered

The application layer

The top Layer, which we can directly touch, is the Application Layer. The Application software that we use on computers or mobile phones is implemented in the Application Layer. Then, when two applications on different devices need to communicate, the application passes the application data to the next layer, the transport layer. Therefore, the application layer only needs to focus on providing application functions for users, and does not care about how data is transmitted, just like when we send express, we only need to hand the package to the Courier, who is responsible for the delivery of express, we do not need to care about how fast is transported. And the application layer works in the user mode of the operating system, the transport layer and below work in the kernel mode.Copy the code

The transport layer

Transport Layer The Transport Layer provides network support for the application Layer

Transmission Control Protocol (TCP) and UDP(UDP) at the transport layer

  • TCP is called transport Layer control protocol and is widely used. Many more features than UDP, such as flow control, timeout retransmission, congestion control and so on, resulting in more reliable
  • UDP simple, simple to only responsible for sending data packets, but real-time better transmission efficiency is higher

Applications require data transmission can be very big, if not good control directly, so when the packet size exceeds MSS of the transport layer (TCP maximum message length), is to block the packet, so that even if the way have a block is lost or damaged, only need to this a block, instead of resend the packet. In TCP, we call each Segment a TCP Segment.

When the device is the receiver, the transport layer is responsible for sending packets to the application. However, there may be many applications receiving or transmitting data on a single device, so a number is needed to distinguish the applications. This number is the port.

For example, port 80 is usually used by the Web server, and port 22 is usually used by the remote login server. Each TAB bar in the browser (client) is a separate process, and the operating system assigns temporary port numbers to these processes.

Packets at the transport layer carry port numbers. Therefore, the receiver can identify the application to which the packet is sent.Copy the code

The network layer

We don’t want the transport Layer protocol to handle too much, we just need to serve the application well, let it serve as the medium of data transfer between applications, to help implement the communication between applications, and the actual transmission function is left to the next Layer, namely the Internet Layer.

** D The IP Protocol is most commonly used at the network layer. Internet Protocol IP packets are composed of the IP header and packets at the transport layer. If the size of an IP packet exceeds the MTU, the MTU is 1500 bytes

In order to find another device, you need a number that distinguishes devices

In ipv4, IP addresses are 32 bits, divided into four 8-bit segments. For faster addressing, there are two types of IP addresses

  • Subnet number
  • The host

In addition to addressing capability another capability is routing

Actual scenario, the two devices is not use a network cable connected, but by many gateways, routers, switches, and so on a number of network devices connected, so can form many network path, so when the packets to a network node, you need the algorithm decide which path to go next.

So IP addresses tell us which way to go to the next destination, and routing selects a path based on the “next destination.” Addressing is more like navigation, routing is more like steering.

Data link layer

Once data is transferred across a network, there needs to be a device on both networks. This device is usually a router, which calculates the next IP address from the routing table.

So how does the router know which device the IP address belongs to?

Therefore, it is necessary to have a special Layer to identify devices in the network and transmit Data in a Link. This is the Data Link Layer, which mainly provides link-level transmission services for the network Layer.

The network adapter of each device has a MAC address, which uniquely identifies the device. The router calculates the IP address of the next destination and uses ARP to find the MAC address of the destination. In this way, it knows which device belongs to the IP address.

The physical layer

When a device connects to a network, it needs to convert data packets into electrical signals so that they can be transmitted in physical media. This is the Physical Layer, which provides binary transport services for the data link Layer

conclusion

There are five levels,

  • Application has been
  • Transport layer TCP/UDP Control Protocol /
  • Network layer IP Protocol Internet Protocol. IPV4,IPV6, etc
  • Data link layer -> Routers across the network
  • Physical layer binary data is converted to electrical signals