"Network Protocol" TCP interactive data stream and data stream block

Source: Internet
Author: User

Preface

There are many application layer protocols based on the TCP protocol, such as FTP, HTTP, Telnet, etc., which can be divided into two categories depending on how much data is transferred: the type of interaction and the block data.

Interactive data types, such as Telnet, are typically only small-traffic data exchanges. For example, each time you press a key, you echo some characters.

Block data types. such as: FTP, such protocols need to transfer more data. Generally, the amount of data transmitted is relatively large.

For these two different situations, TCP adopts different strategies for data transmission.


Interactive Data Flow

For applications where interactivity is more demanding, such as Rlogin telnet, you need to echo the characters entered by the client, each sending a byte to the server. and echo back to the client steps such as the following:

1. The client generates a 41bit long message (20 byte IP header. 20 bytes of TCP header, 1 bytes of data). Sent to the service side;

2, the server sent over a 40bit confirmation message.

3, the service side sends the echo character. The message length is 41bit;

4, the client sends confirmation message. The message length is 40bit.

Suppose that in a local area network, there is usually no trouble, because the LAN generally does not appear congested, but in the WAN. These small groupings add the potential for network congestion to occur. in order to improve the transmission efficiency and reduce the burden of this kind of data , TCP adopts two strategies: the piggyback ack and the Nagle algorithm.

Piggyback ack

Piggyback ack means that when the receiver receives a TCP message segment, does not immediately send an ACK message, but wait for a period of time, assuming that the host has data to be sent to the remote host, the data will be sent on the ACK together with the past, very obvious. This can reduce the transport overhead. To prevent a time-out retransmission from being generated. Most of the cases. This wait time is 200ms, more than 200ms, assuming no data to send together. The ACK message is sent directly.

The strategy of the piggyback ACK is generally only used in highly interactive applications, and for block traffic, most applications do not send data in two directions at the same time.

Nagle algorithm

The focus of the algorithm is to require more than one group on a TCP connection to have an unconfirmed datagram in transit.

The approximate idea of the algorithm is as follows: The application sends the data to be sent byte-by-bit from the send cache to the TCP, sending a portion of the data from the line surface first. And the subsequent bytes are cached, and when the sender receives the acknowledgement of the preceding byte, it then assembles all the data in the sending buffer into a message segment to send. At the same time continue to cache the data that comes next. The ability to continue sending the next message segment only after receiving confirmation from the previous message segment. Other than that. The Nagle algorithm also stipulates that when the data in the sending cache has reached half the size of the sending form or has reached the MSS value of the message segment, a message segment is sent immediately.

This method can significantly reduce the network bandwidth used when the data arrives faster and the network rate is slow. Very obvious. The algorithm is also designed for highly interactive applications, for block-based data flow. Assume that the next message segment is sent each time a confirmation is received. Then the transfer rate will be very low.


Block Data Streams

For some applications with high data throughput requirements, it is always desirable to send as much data as possible to the host each time. For such applications, TCP uses the sliding form protocol, which allows the sender to send multiple packets in succession before stopping and waiting for confirmation, thus speeding up the transfer of data.

Sliding Form

The slide of a sliding form is measured in bytes. Sender A and receiver B negotiate the size of the Send form and accept form at the first two handshakes of the TCP three handshake, and sender a confirms the size of the form indicated in the connection message as sent by B. To determine the maximum amount of data sent before the acknowledgement is received. Assume that the form size indicated in the acknowledgement message received by B is 0. To stop sending the data. Continue sending until a confirmation message is received that is not 0. The Send form indicates that a can send the data in the window continuously without receiving the confirmation of B, and that all the data that has been sent will be kept temporarily until the confirmation is received. To use when the retransmission is timed out.

It is important to note that when using the TCP sliding form protocol, the receiver does not have to acknowledge each received grouping. In TCP. ACK acknowledgement is cumulative, can only send an ACK acknowledgement message after receiving several sequential sequence of packets, but the cumulative wait time can not exceed 0.5 seconds, in order to prevent the sending side timeout retransmission.

Also, be aware of the three variations of the sliding form:

1. The form closes. The left edge of the form is close to the right edge. This happens when the data is sent and the acknowledgement is received;

2. Open the form. Move to the right edge of the form to indicate that you have agreed to send a lot of other data. This happens when the receiving process on one end reads the confirmed data from the TCP receive cache.

3, the form shrinks.

The right edge of the form moves to the left, usually very rarely, and the RFC strongly does not recommend this, as it is very likely that some errors will occur. For example, some data has been sent out, but also shrink the form, not to send the data.

In addition, the left edge of the form is certainly not possible to move left, assuming that it receives an ACK indicating that the left edge of the form moves to the left, it is considered to be a repeated ack. and is discarded.

Summarize the following points:

1, the sender does not have to send a full form size of data, one time to send a portion of it.

2, the size of the form can be reduced. However, the right edge of the form cannot be moved to the left.

3. The receiving party does not have to wait for the form to fill before sending an ACK.

4, the size of the form is relative to the confirmation ordinal. The left edge of the form after receipt of confirmation starts with the confirmation number.

Send Receive Buffer

This section mainly understand the points:

1, buffer space and ordinal space are limited, and are recycled.

2, the form size must not be larger than the size of the transceiver buffer

3. The send buffer is used to stage the TCP message segment that the sender prepares to send and the data that has been sent but not yet received.

4, the receiving buffer is used to temporarily arrive but has not yet been read by the upper-level application data is not ordered to arrive.

    

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

"Network Protocol" TCP interactive data stream and data stream block

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.