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

查看:132
本文介绍了在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?

EDIT :问题来自应用程序观点看法。如果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.

流表示从接收者的角度看没有消息边界。

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.

编辑:您可以获得一条1000字节的消息或一千条1字节的消息,具体取决于下面的内容和调用读取/让我从应用程序的角度澄清。不,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天全站免登陆