TCP和数据有效性

时间:2013-06-12 19:13:59

标签: tcp tcpclient network-protocols

我知道TCP实现了有序数据传输,但实际上是否验证了从A到B到达的数据是从A发送的实际数据? 如果确实如此,它究竟是如何发生的?

2 个答案:

答案 0 :(得分:1)

  

它是否实际验证从A到B到达的数据是从A发送的实际数据?

坦率地说,没有。 它试图确保接收者在会话期间获得与发送者相同的字节数(使用ack和syn数字)。它还确保每个段都有正确的校验和,我认为这并不能保证。如果你的主机有错误的内存,可能是你发送一个字节流,然后,一些缓冲区后来另一个字节流(由于位抖动)用于计算校验和。校验和将是正确的,但发送和接收的消息将有所不同。如果您需要可靠性,请始终实施自己的应用程序级消息的校验和/散列/签名。

一些相关的读数解释了单个位错误的成本:http://status.aws.amazon.com/s3-20080720.html

答案 1 :(得分:0)

我相信RFC 793的这段摘录可以回答你的问题:

The TCP must recover from data that is damaged, lost, duplicated, or
delivered out of order by the internet communication system.  This
is achieved by assigning a sequence number to each octet
transmitted, and requiring a positive acknowledgment (ACK) from the
receiving TCP.  If the ACK is not received within a timeout
interval, the data is retransmitted.  At the receiver, the sequence
numbers are used to correctly order segments that may be received
out of order and to eliminate duplicates.  Damage is handled by
adding a checksum to each segment transmitted, checking it at the
receiver, and discarding damaged segments.