Unpacking mechanism of TCP protocol
When the length of the sender buffer is greater than the MTU of the network card, TCP will split the data sent this time into several data packets and send it out.
MTU is the abbreviation of Maximum Transmission Unit. It means the largest packet transmitted on the network. The unit of MTU is a byte. Most network devices have an MTU of 1500. If the MTU of the machine is larger than the MTU of the gateway, large packets will be disconnected and transmitted, which will generate a lot of packet fragmentation
Stream-oriented communication characteristics and Nagle algorithm
TCP (transport control protocol) is a connection-oriented, stream-oriented, high-reliability service.
Both ends of the transceiver (client and server) must have a pair of sockets. Therefore, the sender uses the optimization method (Nagle algorithm) in order to send multiple packets to the receiver more efficiently. Combine data with small intervals and small data volume into one large data block, and then perform packetization.
In this way, the receiving end is difficult to distinguish, and a scientific unpacking mechanism must be provided. That is, stream-oriented communication is borderless with message protection.
For empty messages: TCP is based on data flow, so the message sent and received cannot be empty, TCP is an important topic of CCNP. And SPOTO's CCNP dumps can help you get certified faster.learningwhich requires the addition of a null message processing mechanism on both the client and the server to prevent the program from getting stuck, and up is based on datagrams, even Yes, you input the empty content (direct carriage return), you can also be sent, the UDP protocol will help you package the message header to send the past.
Reliable sticky TCP protocol: TCP protocol data will not be lost, no packet is received, next time receiving, will continue to receive the last time, the terminal will always clear the buffer content when receiving an ack. The data is reliable, but it will stick.
User mode and kernel mode description during socket data transmission
The sender can send data in a K-K, and the application at the receiving end can pick up the data in two K and two K. Of course, it is also possible to pick up 3K or 6K data at a time, or only take a few bytes of data at a time.
In other words, the data seen by the application is a whole, or a stream, how many bytes of a message are invisible to the application, so the TCP protocol is a stream-oriented protocol, which is also easy. The cause of the sticky package problem.
UDP is a message-oriented protocol. Each UDP segment is a message. The application must extract data in units of messages. It cannot extract arbitrary bytes of data at a time. This is very different from TCP.
How to define a message? It can be considered that the data of the other party's write/send is a message. It needs to be understood that when the other party sends a message, no matter how the underlying segment is fragmented, the TCP protocol layer will sort the data segments constituting the entire message. Rendered in the kernel buffer.
For example, a TCP-based socket client uploads a file to a server. When the file is sent, the content of the file is sent according to a byte stream. After the receiver sees it, it does not know where the byte stream of the file starts. Where is it over?
UDP does not stick out
UDP (user datagram protocol) is a connectionless, message-oriented, high-efficiency service.
The block's merge optimization algorithm is not used. Since UDP supports a one-to-many mode, the receiver's skbuff (socket buffer) uses a chain structure to record each incoming UDP packet, in each UDP. There is a message header (message source address, port, etc.) in the packet so that it is easy for the receiving end to distinguish. That is, message-oriented communication has a message protection boundary.
For empty messages: TCP is based on data flow, so the message sent and received cannot be empty, which requires the addition of a null message processing mechanism on both the client and the server to prevent the program from getting stuck, and up is based on datagrams, even Yes, you input the empty content (direct carriage return), you can also be sent, the UDP protocol will help you package the message header to send the past.
Unreliable non-adhesive UDP protocol: UDP's recvfrom is blocked, and a recvfrom(x) must be a unique sending(y), which is a number of x bytes.
The sticky phenomenon only occurs in the top protocol:
1. On the surface, the sticky problem is mainly due to the cache mechanism of the sender and the receiver, and the TCP protocol is oriented to stream communication.
2. In fact, it is mainly because the receiver does not know the boundary between the messages and does not know how many bytes of data are extracted at one time.