TCP流与UDP消息 [英] TCP stream vs UDP message

查看:72
本文介绍了TCP流与UDP消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TCP是面向流的,这意味着数据将作为连续的字节流进行传输.但是令我困惑的是,TCP创建段并将其传递给IP. IP创建数据包封装段并进行传输.那么这里的连续流到底在哪里呢?

TCP is stream oriented meaning data is transferred as a continues stream of bytes. But what confuses me is that TCP creates segments and passes this down to IP. IP creates packets encapsulates segments and transfers them. So where exactly the continuous stream here?

UDP是面向消息的.它从应用程序层接收消息,创建数据报并将其下推到IP.到目前为止,它与TCP相同,只是创建并下推了数据报.是什么使该协议成为面向消息的?

UDP on the other hand is message oriented. It receives messages from application layer, creates datagrams and pushes it down to IP. So far it is the same as TCP, instead a datagram created and pushed down. What makes this protocol a message oriented?

推荐答案

为这些协议的用户(程序员)提供给您的接口/API是:

The interface/API presented to you the user(programmer) of these protocols are:

UDP

面向消息,您拥有一个API(发送/接收和类似内容),可让您发送 一个数据报,并接收一个数据报. 1个send()调用导致发送1个数据报,而1个recv()调用将恰好接收1个数据报.

Message oriented, you have an API (send/recv and similar) that provide you with the ability to send one datagram, and receive one datagram. 1 send() call results in 1 datagram sent, and 1 recv() call will recieve exactly 1 datagram.

TCP

面向流,您有一个API(发送/接收和类似命令),使您能够发送或接收字节流.无法保留消息边界,TCP可以将来自多个send()调用的数据捆绑成一个段,也可以将来自一个send()调用的数据分解成多个段-但这对于坐在TCP之上的应用程序是透明的, recv()只是给您返回数据,与有多少send()调用产生的数据无关.

Stream oriented, you have an API (send/recv and similar) that gives you the ability to send or receive a byte stream. There is no preservation of message boundaries, TCP can bundle up data from many send() calls into one segment, or it could break down data from one send() call into many segments - but that's transparent to applications sitting on top of TCP, and recv() just gives you back data, with no relation to how many send() calls produced the data you get back.

这篇关于TCP流与UDP消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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