C# UDP 套接字的 ReceiveBufferSize 是否适用于数据报的大小或消息队列的大小?
Does C# UDP socket's ReceiveBufferSize applies to size of datagrams or size of the message queue?
我有一个托管在 Azure 云上的 C# UDP 套接字,它使用 UdpClient.receive
接收 UDP 数据报。可能有数千个客户端同时向套接字发送消息,每个客户端发送大小约为 1Kb 的数据报。
我很困惑 ReceiveBufferSize
是否适用于每个数据报的大小,或者它是否设置了下面的接收队列的大小?通过接收队列,我的意思是 .NET 运行时使用的队列来排队来自 UdpClient.receive
尚未读取的不同客户端的数据报。
我在一些帖子中看到 ReceiveBufferSize
仅适用于单个数据报的大小,如果是这样,我们如何设置下面的接收队列的大小?
我已将 ReceiveBufferSize
设置为 65Kb。如果 ReceiveBufferSize
适用于引擎盖下的队列大小,并且每个客户端同时发送一个 1Kb 数据报,这是否意味着套接字只能处理来自 65 个客户端的数据?如果有更多的客户端同时发送缓冲区溢出和数据报丢失?
大概你的意思是 UdpClient.Client.ReceiveBufferSize
,即 Socket.ReceiveBufferSize
?
如果您继续调用该调用,您最终会使用 SO_RCVBUF
选项调用 setsockopt
here。
研究那个选项,你最终在 this answer 来自 @DS:
SO_RCVBUF
is simpler to understand: it is the size of the buffer the kernel allocates to hold the data arriving into the given socket during the time between it arrives over the network and when it is read by the program that owns this socket. With TCP, if data arrives and you aren't reading it, the buffer will fill up, and the sender will be told to slow down (using TCP window adjustment mechanism). For UDP, once the buffer is full, new packets will just be discarded.
这表明它是与套接字关联的整个队列的大小,即 OS 将接收到的 UDP 数据报放入其中供您读取的缓冲区有多大。一旦它已满,额外的数据报将被丢弃。
我有一个托管在 Azure 云上的 C# UDP 套接字,它使用 UdpClient.receive
接收 UDP 数据报。可能有数千个客户端同时向套接字发送消息,每个客户端发送大小约为 1Kb 的数据报。
我很困惑 ReceiveBufferSize
是否适用于每个数据报的大小,或者它是否设置了下面的接收队列的大小?通过接收队列,我的意思是 .NET 运行时使用的队列来排队来自 UdpClient.receive
尚未读取的不同客户端的数据报。
我在一些帖子中看到 ReceiveBufferSize
仅适用于单个数据报的大小,如果是这样,我们如何设置下面的接收队列的大小?
我已将 ReceiveBufferSize
设置为 65Kb。如果 ReceiveBufferSize
适用于引擎盖下的队列大小,并且每个客户端同时发送一个 1Kb 数据报,这是否意味着套接字只能处理来自 65 个客户端的数据?如果有更多的客户端同时发送缓冲区溢出和数据报丢失?
大概你的意思是 UdpClient.Client.ReceiveBufferSize
,即 Socket.ReceiveBufferSize
?
如果您继续调用该调用,您最终会使用 SO_RCVBUF
选项调用 setsockopt
here。
研究那个选项,你最终在 this answer 来自 @DS:
SO_RCVBUF
is simpler to understand: it is the size of the buffer the kernel allocates to hold the data arriving into the given socket during the time between it arrives over the network and when it is read by the program that owns this socket. With TCP, if data arrives and you aren't reading it, the buffer will fill up, and the sender will be told to slow down (using TCP window adjustment mechanism). For UDP, once the buffer is full, new packets will just be discarded.
这表明它是与套接字关联的整个队列的大小,即 OS 将接收到的 UDP 数据报放入其中供您读取的缓冲区有多大。一旦它已满,额外的数据报将被丢弃。