了解 TCP 中的缓冲
Understanding buffering in TCP
我正在 Java 中编写一个 tcp 客户端,它应该从某个服务器接收数据。
据我所知,如果客户端无法处理来自服务器的传入数据,OS 将开始缓冲数据。但是如果缓冲区满了怎么办?这种行为是可配置的吗?
我的意思是我想限制服务器数据流,直到客户端可以处理数据,这样数据才不会丢失。可能吗?
您描述的是 TCP 窗口。
有一个很好的解释here
摘录:
When discussing TCP Windows, we are most often referring to the TCP Receive Window. Simply put, a TCP Receive Window is a buffer on each side of the TCP connection that temporarily holds incoming data. The data in this buffer is sent to the application, clearing more room for incoming data. If this buffer fills up, the receiver of the data will alert the sender that no more data can be received until the buffer is cleared. There are several more details involved, that that is the basic function. A device advertises the current size of its TCP Window in the TCP Header information.
可以通过关闭 window 来限制流,尽管您可以轻松地停止从缓冲区读取数据并让协议完成它的工作。
一些消息传递产品通过使用辅助缓冲区来管理此问题,以最大限度地减少数据溢出的影响。不过,这些产品中的大多数主要是 UDP broadcast/multicast。但在某种程度上,如果您的客户跟不上,您就会遇到问题。
我正在 Java 中编写一个 tcp 客户端,它应该从某个服务器接收数据。
据我所知,如果客户端无法处理来自服务器的传入数据,OS 将开始缓冲数据。但是如果缓冲区满了怎么办?这种行为是可配置的吗?
我的意思是我想限制服务器数据流,直到客户端可以处理数据,这样数据才不会丢失。可能吗?
您描述的是 TCP 窗口。
有一个很好的解释here
摘录:
When discussing TCP Windows, we are most often referring to the TCP Receive Window. Simply put, a TCP Receive Window is a buffer on each side of the TCP connection that temporarily holds incoming data. The data in this buffer is sent to the application, clearing more room for incoming data. If this buffer fills up, the receiver of the data will alert the sender that no more data can be received until the buffer is cleared. There are several more details involved, that that is the basic function. A device advertises the current size of its TCP Window in the TCP Header information.
可以通过关闭 window 来限制流,尽管您可以轻松地停止从缓冲区读取数据并让协议完成它的工作。
一些消息传递产品通过使用辅助缓冲区来管理此问题,以最大限度地减少数据溢出的影响。不过,这些产品中的大多数主要是 UDP broadcast/multicast。但在某种程度上,如果您的客户跟不上,您就会遇到问题。