在TCP接收数据 [英] Receiving data in TCP

查看:236
本文介绍了在TCP接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在TCP发送1000个字节,不能保证接收器将会得到整个1000字节togther? ?或者他会先只得到500个字节,后来他就会收到其它字节

If i send 1000 bytes in TCP, does it guarantee that the receiver will get the entire 1000 bytes "togther"? or perhaps he will first only get 500 bytes, and later he'll receive the other bytes?

修改:这个问题是来自应用程序的观点看法。如果1000字节是重组为一个缓冲区他们到达应用程序之前..然后我不在乎,如果它的方式。

EDIT: the question comes from the application's point of view. If the 1000 bytes are reassembles into a single buffer before they reach the application .. then i don't care if it was fragmented in the way..

推荐答案

请参见传输控制协议

TCP提供可靠的,有序的字节流的传递从程序一台计算机到另一台计算机上的其他程序。

TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer.

一个流是指存在来自来看接收器的点没有边界。你可以得到一个1000字节的消息或者根据什么下,你选择如何经常读/选择千1字节的信息

A "stream" means that there is no message boundary from the receiver's point of view. You could get one 1000 byte message or one thousand 1 byte messages depending on what's underneath and how often you call read/select.

修改:让我但从应用的角度澄清。不,TCP不能保证单读会给你所有的1000个字节(或1MB或1GB)数据包发送者可能就差了。因此,上面的TCP的协议通常包含在它的总内容长度固定长度的头。例如,你可以随时发送1个字节,表示字节的内容,这将支持最多255个字节的总长度。

Edit: Let me clarify from the application's point of view. No, TCP will not guarantee that the single read would give you all of the 1000 bytes (or 1MB or 1GB) packet the sender may have sent. Thus, a protocol above the TCP usually contains fixed length header with the total content length in it. For example you could always send 1 byte that indicates the total length of the content in bytes, which would support up to 255 bytes.

这篇关于在TCP接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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