• <i id='JBGfc'><tr id='JBGfc'><dt id='JBGfc'><q id='JBGfc'><span id='JBGfc'><b id='JBGfc'><form id='JBGfc'><ins id='JBGfc'></ins><ul id='JBGfc'></ul><sub id='JBGfc'></sub></form><legend id='JBGfc'></legend><bdo id='JBGfc'><pre id='JBGfc'><center id='JBGfc'></center></pre></bdo></b><th id='JBGfc'></th></span></q></dt></tr></i><div id='JBGfc'><tfoot id='JBGfc'></tfoot><dl id='JBGfc'><fieldset id='JBGfc'></fieldset></dl></div>
    <legend id='JBGfc'><style id='JBGfc'><dir id='JBGfc'><q id='JBGfc'></q></dir></style></legend>

    <small id='JBGfc'></small><noframes id='JBGfc'>

        <bdo id='JBGfc'></bdo><ul id='JBGfc'></ul>

      1. <tfoot id='JBGfc'></tfoot>

        在 Python 中读取 UDP 数据包的缓冲区大小

        时间:2023-09-28
        <tfoot id='aw4ip'></tfoot>

            <tbody id='aw4ip'></tbody>
        1. <i id='aw4ip'><tr id='aw4ip'><dt id='aw4ip'><q id='aw4ip'><span id='aw4ip'><b id='aw4ip'><form id='aw4ip'><ins id='aw4ip'></ins><ul id='aw4ip'></ul><sub id='aw4ip'></sub></form><legend id='aw4ip'></legend><bdo id='aw4ip'><pre id='aw4ip'><center id='aw4ip'></center></pre></bdo></b><th id='aw4ip'></th></span></q></dt></tr></i><div id='aw4ip'><tfoot id='aw4ip'></tfoot><dl id='aw4ip'><fieldset id='aw4ip'></fieldset></dl></div>

              <legend id='aw4ip'><style id='aw4ip'><dir id='aw4ip'><q id='aw4ip'></q></dir></style></legend>

                • <bdo id='aw4ip'></bdo><ul id='aw4ip'></ul>

                  <small id='aw4ip'></small><noframes id='aw4ip'>

                • 本文介绍了在 Python 中读取 UDP 数据包的缓冲区大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试找出/调整网络缓冲区的大小:

                  导入套接字袜子 = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)sock.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)212992

                  这到底是什么?~ 0.2 MB ..!?

                  但是,如果我在其他地方(即在命令行上)寻找缓冲区大小:

                  sampsa@sampsa-xps13:~/python/sockets$ cat/proc/sys/net/ipv4/tcp_wmem4096 16384 4194304

                  .. 我得到 4096 个字节.

                  让我们尝试设置缓冲区大小,然后检查它的值:

                  sock.setsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF,1024)sock.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)2304

                  发生了什么事?

                  将 SOL_SOCKET 替换为 SOL_UDP 会给出协议不可用"

                  如何调整最大值.UDP数据包的大小..甚至找出来?

                  解决方案

                  我想说,如何找出/调整缓冲区的大小

                  您使用 SO_RCVBUF 的方式是正确的.但请注意,根据您的设置和操作系统,您使用 getsockopt 返回的值可能与使用 setsockopt 设置的值不同.在 Linux socket(7) 状态下:

                  SO_RCVBUF设置或获取最大套接字接收缓冲区(以字节为单位).内核加倍此值(为簿记开销留出空间)时使用setsockopt(2),这个加倍的值由 getsockopt(2) 返回.默认值由/proc/sys/net/core/rmem_default 文件设置,并且最大允许值由/proc/sys/net/core/rmem_max 文件设置.此选项的最小(加倍)值为 256.

                  <块引用>

                  顺便说一句,网络套接字是 FIFO 吗?first in - 当缓冲区饱和时首先丢弃?

                  据我所知,如果缓冲区已满,接收将失败.它不会丢弃已接收但未处理的数据以为新数据腾出空间.

                  I am trying to find out / adjust the size of network buffers:

                  import socket
                  
                  sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
                  
                  sock.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)
                  212992
                  

                  What on earth is this? ~ 0.2 MBytes ..!?

                  However, if I am looking for the buffer size elsewhere, i.e. on the command line:

                  sampsa@sampsa-xps13:~/python/sockets$ cat /proc/sys/net/ipv4/tcp_wmem
                  4096    16384   4194304
                  

                  .. I get 4096 bytes.

                  Let's try to set the buffer size and then check its value:

                  sock.setsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF,1024)
                  
                  sock.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)     
                  2304
                  

                  What's going on?

                  Substituting SOL_SOCKET with SOL_UDP gives "Protocol not available"

                  How can I adjust the max. size of the UDP packet .. or even find it out?

                  解决方案

                  I wanted to say, how to find out / adjust the size of the buffer

                  The way you did with SO_RCVBUF was correct. But note that depending on your setting and on your OS you might get different values back with getsockopt than you set with setsockopt. On Linux socket(7) states:

                  SO_RCVBUF
                  Sets or gets the maximum socket receive buffer in bytes.  The kernel doubles
                  this value (to allow space for bookkeeping overhead) when it is set using 
                  setsockopt(2), and this doubled  value  is  returned  by  getsockopt(2). 
                  The default value is set by the /proc/sys/net/core/rmem_default file, and
                  the maximum allowed value is set by the /proc/sys/net/core/rmem_max file.  
                  The minimum (doubled) value for this option is 256.
                  

                  And, btw, are the network sockets FIFO ? first in - first discarded when the buffer gets saturated?

                  As far as I know if the buffer is full receiving will fail. It will not discard already received but not processed data to make room for new data.

                  这篇关于在 Python 中读取 UDP 数据包的缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:侦听 UDP 数据包的 Python 原始套接字;只收到一半的数据包 下一篇:写入 UDP 套接字会阻塞吗?

                  相关文章

                • <small id='2cS4i'></small><noframes id='2cS4i'>

                  <legend id='2cS4i'><style id='2cS4i'><dir id='2cS4i'><q id='2cS4i'></q></dir></style></legend>

                  <tfoot id='2cS4i'></tfoot>
                  <i id='2cS4i'><tr id='2cS4i'><dt id='2cS4i'><q id='2cS4i'><span id='2cS4i'><b id='2cS4i'><form id='2cS4i'><ins id='2cS4i'></ins><ul id='2cS4i'></ul><sub id='2cS4i'></sub></form><legend id='2cS4i'></legend><bdo id='2cS4i'><pre id='2cS4i'><center id='2cS4i'></center></pre></bdo></b><th id='2cS4i'></th></span></q></dt></tr></i><div id='2cS4i'><tfoot id='2cS4i'></tfoot><dl id='2cS4i'><fieldset id='2cS4i'></fieldset></dl></div>

                  • <bdo id='2cS4i'></bdo><ul id='2cS4i'></ul>