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

      • <bdo id='guDbA'></bdo><ul id='guDbA'></ul>
    1. <legend id='guDbA'><style id='guDbA'><dir id='guDbA'><q id='guDbA'></q></dir></style></legend>

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

        <tfoot id='guDbA'></tfoot>
      1. 如何通过 localhost 使用多播限制流量

        时间:2024-04-21

          <legend id='MuYZa'><style id='MuYZa'><dir id='MuYZa'><q id='MuYZa'></q></dir></style></legend>
            <tbody id='MuYZa'></tbody>
          <tfoot id='MuYZa'></tfoot>

              <bdo id='MuYZa'></bdo><ul id='MuYZa'></ul>
              1. <small id='MuYZa'></small><noframes id='MuYZa'>

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

                • 本文介绍了如何通过 localhost 使用多播限制流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I'm using multicast UDP over localhost to implement a loose collection of cooperative programs running on a single machine. The following code works well on Mac OSX, Windows and linux. The flaw is that the code will receive UDP packets outside of the localhost network as well. For example, sendSock.sendto(pkt, ('192.168.0.25', 1600)) is received by my test machine when sent from another box on my network.

                  import platform, time, socket, select
                  
                  addr = ("239.255.2.9", 1600)
                  
                  sendSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
                  sendSock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 24)
                  sendSock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, 
                      socket.inet_aton("127.0.0.1"))
                  
                  recvSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
                  recvSock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
                  if hasattr(socket, 'SO_REUSEPORT'):
                      recvSock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, True)
                  
                  recvSock.bind(("0.0.0.0", addr[1]))
                  status = recvSock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, 
                      socket.inet_aton(addr[0]) + socket.inet_aton("127.0.0.1"));
                  
                  while 1:
                      pkt = "Hello host: {1} time: {0}".format(time.ctime(), platform.node())
                      print "SEND to: {0} data: {1}".format(addr, pkt)
                      r = sendSock.sendto(pkt, addr)
                  
                      while select.select([recvSock], [], [], 0)[0]:
                          data, fromAddr = recvSock.recvfrom(1024)
                          print "RECV from: {0} data: {1}".format(fromAddr, data)
                  
                      time.sleep(2)
                  

                  I've attempted to recvSock.bind(("127.0.0.1", addr[1])), but that prevents the socket from receiving any multicast traffic. Is there a proper way to configure recvSock to only accept multicast packets from the 127/24 network, or do I need to test the address of each received packet?

                  解决方案

                  Unfortunately, multicast IP doesn't have any such "filtering by subnetwork" feature -- so, unless you want to muck with IPTables (on Linux) or equivalent "firewall" SW/HW of your system/network to try and "drop on the floor" every multicast packet you don't like, I think you'll have to do it at application level (with a test on fromAddr in your inner loop, for example). Is the IP traffic from other hosts so much it degrades your performance...?

                  这篇关于如何通过 localhost 使用多播限制流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:AttributeError:“设置"对象没有属性“ROOT_URLCONF" 下一篇:如何制作良好的可重现 pandas 示例

                  相关文章

                • <tfoot id='rnANR'></tfoot>

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

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

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