什么是SOCK_DGRAM和SOCK_STREAM? [英] What is SOCK_DGRAM and SOCK_STREAM?

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

问题描述

我刚遇到一个奇怪的事情,我发现应用程序默认情况下使用 SOCK_STREAM 函数。为什么会这样呢?这个 SOCK_STREAM 只是创建多个流吗?还是标准的 SOCK_STREAM 函数可用于创建TCP流?

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)?

我以为海啸是基于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数据包丢失,发送方可以告知。

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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