数据传输时如何知道服务器收到的最后一个TCP报文段是哪一个?

发布于 2024-08-23 00:10:04 字数 99 浏览 12 评论 0原文

当使用 TCP 传输数据时,给定所有传入和传出的数据包,如何知道收到的数据包是否是最后一个数据?

TCP 数据包被分成更小的部分。我正在通过 HTTP 协议进行传输。

When transferring data in TCP, and given all the incoming and outcoming packets, how will one know if the packet received is the last of the data?

TCP packets are fragmented into smaller parts. I'm transferring over the HTTP protocol.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉南桥 2024-08-30 00:10:04

您可以使用 TCP 协议的 PSH 标志。在最后一个数据包中应将其设置为 1。

要确认这一点,只需开始跟踪,进行 HTTP GET 并过滤会话。您会发现 HTTP GET 上每个响应的最后一个数据包都标有此标志。

You might use PSH flag of TCP protocol. It should be set to 1 in last packet.

To confirm this just start tracing, make HTTP GET and filter session. You will find that last packet for each response on your HTTP GET is marked by this flag.

陌上青苔 2024-08-30 00:10:04

当连接的一端设置 FIN 标志时,表示该端将不再发送数据。

如果在最后一个数据之后连接没有关闭,那么必须有一个应用程序层方法来确定它。对于 HTTP,规则相当复杂。

When the FIN flag is set by one end of the connection, it indicates that that end will not be sending anymore data.

If the connection is not being closed after the last of the data, then there must be an application-layer method of determining it. For HTTP, the rules are reasonably complicated.

纵山崖 2024-08-30 00:10:04

我假设您正在使用某种套接字库。您可以判断 TCP 连接已完成,因为套接字上的 read() 将返回 0。当另一方关闭连接时就会发生这种情况(它永远不必这样做)。

I'm assuming you're using some sort of socket library. You can tell a TCP connection is finished because a read() on the socket will return 0. This will happen when the other side closes the connection (which it never has to do).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文