SOCK_DGRAM 和 SOCK_STREAM 是什么?

What is SOCK_DGRAM and SOCK_STREAM?(SOCK_DGRAM 和 SOCK_STREAM 是什么?)

本文介绍了SOCK_DGRAM 和 SOCK_STREAM 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到一个奇怪的事情,我看到应用程序默认情况下它们使用 SOCK_STREAM 函数.为什么会这样?这是 SOCK_STREAM 只是创建多个流吗?或者它是可用于创建 TCP 流的标准 SOCK_STREAM 函数?

I just came across this strange thing I got to see application is that by default they use SOCK_STREAM function. Why is it so? Is this SOCK_STREAM just creating multiple streams? Or is it the standard SOCK_STREAM function available for creating TCP stream(s)?

我认为 tsunami 是基于 UDP 的,但仍然具有一些类似于 TCP 的功能,例如TCP公平性、友好性等

I thought tsunami is based on UDP, but still having some features like that of TCP, e.g. TCP fairness, friendlyness, etc.

有人可以对这个问题有所了解吗?我对此完全困惑.

Could somebody please shed some light on this issue? I am totally confused over this.

推荐答案

TCP 几乎总是使用 SOCK_STREAM 而 UDP 使用 SOCK_DGRAM.

TCP almost always uses SOCK_STREAM and UDP uses SOCK_DGRAM.

TCP (SOCK_STREAM) 是一种基于连接的协议.连接建立并进行对话,直到连接被其中一方或网络错误终止.

TCP (SOCK_STREAM) is a connection-based protocol. The connection is established and the two parties have a conversation until the connection is terminated by one of the parties or by a network error.

UDP (SOCK_DGRAM) 是一种基于数据报的协议.您发送一个数据报并得到一个回复​​,然后连接终止.

UDP (SOCK_DGRAM) is a datagram-based protocol. You send one datagram and get one reply and then the connection terminates.

  • 如果您发送多个数据包,TCP 承诺按顺序传送它们.UDP 没有,所以接收者需要检查它们,如果命令事项.

  • If you send multiple packets, TCP promises to deliver them in order. UDP does not, so the receiver needs to check them, if the order matters.

如果 TCP 数据包丢失,发送方可以知道.UDP 并非如此.

If a TCP packet is lost, the sender can tell. Not so for UDP.

UDP 数据报有大小限制,从内存中我认为是 512字节.TCP 可以发送比这更大的块.

UDP datagrams are limited in size, from memory I think it is 512 bytes. TCP can send much bigger lumps than that.

TCP 更健壮一点,并进行更多检查.UDP是阴影重量更轻(计算机和网络压力更小).

TCP is a bit more robust and makes more checks. UDP is a shade lighter weight (less computer and network stress).

选择适合您与其他计算机交互方式的协议.

Choose the protocol appropriate for how you want to interact with the other computer.

这篇关于SOCK_DGRAM 和 SOCK_STREAM 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:SOCK_DGRAM 和 SOCK_STREAM 是什么?

基础教程推荐