title: Python sockets -- client not receiving UDP datagram
body: <p><strong>Server code:</strong></p>
  
  <pre><code>s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # server UDP socket
  s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # bypass OS lock on port
  s.bind((socket.gethostname(), 9999)) # bind socket to host and port 9999
  while True:
      message, ip = s.recvfrom(1024) # receive data passed through socket
      print "Server:\n\tMessage \"{}\" received...\n\tIt has a length of {}".format(
              message, len(message))
      s.sendto(str(len(message)), (socket.gethostname(), 9999)) # send message length in bytes back to client
      s.close() # close UDP connection with client
      sys.exit(0) # terminate server process
  </code></pre>
  
  <p><strong>Client code:</strong></p>
  
  <pre><code>s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.connect((socket.gethostname(), 9999))
  message = "Pointless text."
  print "Client:\n\tSending message \"{}\" to the server...\n\tIt has a length of {}".format(
          message, len(message))
  s.sendto(message, (socket.gethostname(), 9999))
  while True:
      response, ip = s.recvfrom(1024)
      if int(response) == len(message):
          print "Client:\n\tThe server returned count {} which is equal to the client's count of {}.".format(response, len(message))
      else:
          print "Client:\n\tThe server returned count {} which is not equal to the client's count of {}.".format(response, len(message))
  s.close()
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Running client in UDP mode...
  Running server in UDP mode...
  
  Client:
      Sending message "Pointless text." to the server...
      It has a length of 15
  Server:
      Message "Pointless text." received...
      It has a length of 15
  </code></pre>
  
  <p>The client side <code>recvfrom</code> never gets triggered and I can't figure out why.</p>
  
  <p>Here are the complete <a href="https://pastebin.com/sGbLNnkd" rel="nofollow noreferrer">client</a> and <a href="https://pastebin.com/qeP8K8aT" rel="nofollow noreferrer">server</a> files if you want to test them directly on your machine like so:</p>
  
  <pre><code>python2.7 server udp &amp; python2.7 client udp
  </code></pre>