如何知道何时完成接收 TCP 流? [英] How to know when you finish receiving a TCP stream?

查看:45
本文介绍了如何知道何时完成接收 TCP 流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当发件人完成向我发送信息时,我不知道如何在 TCP 中告知.

I'm not sure how to tell in TCP when the sender finished sending me the information.

比如A需要向B发送200个字节,B怎么知道A已经发送完毕,信息已经准备好传递给应用层了?

For example if A needs to send 200 bytes to B, how will B know that A finished sending, and that the information is ready to be transferred to the application layer?

有 FIN 标志,但据我所知,它只是象征着您要关闭连接.

There's the FIN flag, but as far as I know it's only there to symbolizes that your going to close the connection.

谢谢.

推荐答案

TCP 没有义务在发送方在连接上完成发送数据时通知接收方.它不能,因为它不了解它正在传输的更高级别的协议数据.

TCP has no obligation to tell the receiver when the sender has finished sending data on the connection. It can't because it has no understanding of the higher level protocol data it's transporting.

但是它会告诉您连接是否关闭(然后您会在网络跟踪中看到一个 FIN、FIN-ACK)序列.从编程的角度来看,假设您使用的是 C,当对等方关闭连接时,函数 recv 将返回 0.

However it will tell you if the connection closes (then you'll see a FIN, FIN-ACK) sequence in a network trace. From a programming perspective, assuming that you're using C the function recv will return 0 when the peer closes the connection.

这篇关于如何知道何时完成接收 TCP 流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆