title: Receiving Broadcast Packets in Python
body: <p>I have the following code which sends a <code>udp</code> packet that is broadcasted in the subnet.</p>
  
  <pre><code>from socket import *
  s=socket(AF_INET, SOCK_DGRAM)
  s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
  s.sendto('this is testing',('255.255.255.255',12345))
  </code></pre>
  
  <p>The following code is for receiving the broadcast packet.</p>
  
  <pre><code>from socket import *
  s=socket(AF_INET, SOCK_DGRAM)
  s.bind(('172.30.102.141',12345))
  m=s.recvfrom(1024)
  print m[0]
  </code></pre>
  
  <p>The problem is that its not receiving any broadcast packet. However, it is successfully receiving normal udp packets sent to that port. </p>
  
  <p>My machine was obviously receiving the broadcast packet, which I tested using <code>netcat</code>.  </p>
  
  <pre><code>$ netcat -lu -p 12345                                             
  this is testing^C
  </code></pre>
  
  <p>So, where exactly is the problem? </p>