### Interactive Communication

That is, the keystrokes are sent from the client to the server individually (one character at a time rather than one line at a time)

this flag is conventionally used to indicate that the buffer at the side sending the packet has been emptied in conjunction with sending the packet

### Delayed Acknowledgements

This is a form of piggybacking that is used most often in conjunction with bulk data transfers

delay发送了更少的ACK，所以能够降低网络中的流量。通常来说，2个分组返回一个ACK是很常见的。

Delaying ACKs causes less traffic to be carried over the network than when ACKs are not delayed because fewer ACKs are used. A ratio of 2 to 1 is fairly com- mon for bulk transfers.

net.inet. tcp.delayed_ack,0:disable delay,1:总是delay 2: ACK every other packet（没隔一个分组确认一次）3: 在2的基础上，自动检测。

### Nagle Algorithm

However, these tinygrams can add to congestion and lead to inefficient use of capacity on wide area networks

Nagle算法的核心非常简单：当一个TCP连接此时有发送但是未被确认的报文的时候，小报文不能被发送，除非之前的数据被确认了，换句话说Nagle算法只能在一个RTT之内发送一个客户端的报文。

The Nagle algorithm says that when a TCP connection has outstanding data that has not yet been acknowledged, small segments (those smaller than the SMSS) cannot be sent until all outstanding data is acknowledged.

The Nagle algorithm says that when a TCP connection has outstanding data that has not yet been acknowledged, small segments (those smaller than the SMSS) cannot be sent until all outstanding data is acknowledged. Instead, small amounts of data are collected by TCP and sent in a single segment when an acknowledgment arrives.

Nagle's algorithm works by combining a number of small outgoing messages and sending them all at once. Specifically, as long as there is a sent packet for which the sender has received no acknowledgment, the sender should keep buffering its output until it has a full packet's worth of output, thus allowing output to be sent all at once.

### Flow Control and Window management

leading to no change of the Window Size field as the connection progresses.

This is accomplished by sending a window advertisement of zero (no space)

#### Sliding Window

• offered window：用于给对方提供数据的窗口，会逐渐滑动，上图中4-9字节就是offered window的长度。offered window的大小，是由接收方在它的window size字段中指定的。

The size of the offered window is controlled by the Window Size field sent by the receiver in each ACK.

• SND.UNA:窗口的左边界，小于SND.UNA即表示已经被确认的数据。
• usable window：窗口中可用的字节数，即offered window中的减去已经被发送但是还未被确认的字节数。上图中的SND.WND是offered window的大小，SND.NXT是下一个可发送的字节offset。usable window = SND.UNA+SND.WND-SND.NXT。上述例子中的带进去就可以了。

1. window close表示的是左边界（SND.UNA）的右移。这会发生在ACK返回的时候和window size变得更小的时候。
2. window open表示的是右边界(SND.UNA+SND.WND)的右移，当接收方的应用程序读取数据的时候，会使得更多的缓存空间被释放。所以offered window也会增大。
3. window shrink发生在窗口右边界左移的时候，虽然RFC 1122不建议这一点， 但是TCP必须能够处理这个。

TCP可以根据对方返回的报文中的ACK和window size字段来调节自己的窗口大小。但是左边界但是不能左移，左边界是由ACK来控制的，因为ACK是不能回退的。当window size并未改变，但是左边界和右边界都移动了，就叫作窗口滑动。如果返回的ACK增加了，但是window size字段减小了，那么左边界右移使得左右边界更加靠近，当两者完全靠在一起的时候，这时就叫作zero window，说明接收方缓冲区没有地方可以存新来的数据了。所以发送方开始探测（probe）对方的窗口，来知道什么时候可以发送。

#### Zero Window and the TCP Persist Timer

TCP的接收方通过它的advertisement window来告知发送方我还有多少数据可以接收。

We have seen that TCP implements flow control by having the receiver specify the amount of data it is willing to accept from the sender: the receiver’ s adver- tised window

Because such updates do not generally contain data (they are a form of “pure ACK”), they are not reliably delivered by TCP

The persist timer triggers the transmission of window probes. Window probes are segments that force the receiver to provide an ACK, which also necessarily contains a Win-dow Size field.

Window probe包含着一个字节的数据，所以TCP可以保证他的可靠传输，这就避免了前面所说的死锁情况。

The probes are sent whenever the TCP persist timer expires, and the byte included may or may not be accepted by the receiver, depending on how much buffer space it has available.

PS: persist timer也会执行exponential back off，和之前多次提到的一样。

#### Example

This is because of an automatic window adjustment algorithm (see Section 15.5.4) that allocates memory to the receiving TCP even if not requested by the application

PS：回想一下，前面ssh的例子中的窗口不变是因为应用程序很快就将发送过来的数据都处理了。与这里的原因不同

#### Silly Window Syndrome

Window-based flow control schemes, especially those that do not use fixed-size segments (such as TCP), can fall victim to a condition known as the silly window syndrome (SWS)

This leads to undesirable inefficiency because each segment has relatively high overhead—a small number ofd ata bytes relative to the number of bytes in the headers.

SWS在发送方和接收方中都会发生：接收方返回了很小的window size，或者发送方发送了很小的数据报。

the receiver can advertise small windows (instead of waiting until a larger window can be advertised), and the sender can transmit small data segments (instead of waiting for additional data to send a larger segment)

1. 当作为接收者的时候，小的window advertisement不能发送。RFC 1122中规定了：发送方不能advertise比当前窗口（可能为0）更大窗口值，直到当前窗口值超过了一个full size segment（receive MSS）或者缓冲区大小的一半，取决于这两个哪个更小。这两种例子可能在如下情形发生：1）应用程序读取了数据，释放了缓冲区。2）发送方发送了window probe。
2. 当作为发送者的时候，不能发送小的报文段，由Nagle算法来决定什么时候发送小的报文段。发送方不传送报文来避免SWS，除非几种情况例外：
3. 一个full size报文可以发送
4. 所发送的数据大小超过了对方所advertise的窗口长度的一半。
5. 满足以下两个条件的时候，想发就发：1）一个ACK不是目前所期望的（也就是说，我们没有outstanding data but unacknowledged）。2）Nagle算法被关闭了

#### SWS Example

PS：不知道这个5秒代表着什么。我猜可能是，TCP本次发送的数据会塞满缓冲区，所以停止一会，期望对方先释放点缓冲区出来，省的开始window probe的环节，这应该也是SWS的策略之一。

showing the characteristic exponential timeout back off.

#### Large Buffers and Auto-Tuning

In most cases, the size specified by the application is effectively ignored, and the operating system instead uses either a large fixed value or a dynamically calculated value

## 发送评论编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
（╯‵□′）╯︵┴─┴
￣﹃￣
(/ω＼)
∠( ᐛ 」∠)＿
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ｀)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ(￣∇￣o)
ヾ(´･ ･｀｡)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò｡)
Σ(っ °Д °;)っ
( ,,´･ω･)ﾉ"(´っω･｀｡)
╮(╯▽╰)╭
o(*////▽////*)q
＞﹏＜
( ๑´•ω•) "(ㆆᴗㆆ)

Emoji