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

查看:31
本文介绍了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天全站免登陆