title: Sending UDP from one computer to another in python
body: <p>I have a pretty standard simple demo for udp packets but I get an error when trying to send to another IP address and I don't really understand why.</p>
  
  <blockquote>
    <p>socketerror: [Errno 22] Invalid argument</p>
  </blockquote>
  
  <p>The code that I thought would work is basically....</p>
  
  <p>Server</p>
  
  <pre><code>def Main():
      host = '0.0.0.0'
      port = 20030
  
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.bind((host,port))
  
      #Then it prints incoming data and sends it back to client.
      data,addr = s.recvfrom(1024)
      s.close()
  </code></pre>
  
  <p>Client</p>
  
  <pre><code>def Main():
      host = '127.0.0.1'
      port = 20020
  
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      s.bind((host,port))
      server = ('10.20.64.115', 20030)
  
      #loop for input to send to server.
      s.sendto(message, server)
      s.close()
  </code></pre>
  
  <p>If I run them both on the same computer and host = 127.0.0.1 on both, both are bound to 127.0.0.1 and s.sendto(message, server) is sending to 127.0.0.1 they can send messages back and for without problems.</p>
  
  <p>If I run them on different computers I believe I'm supposed to use the client to sendto the IP address of the server's IP address but I get the [Errno 22].</p>
  
  <p>So I tried binding the client to 192.0.0.1 that gave an [Errno 99] cannot assign requested address. </p>
  
  <p>I tried binding the client to 0.0.0.0 and the sendto address to 10.20.64.115 but the client just returns to a new line and the server doesn't see anything.</p>
  
  <p>All the tutorials say to bind and sendto 127.0.0.1 so I set both computers to that and it also doesn't show up in the server.</p>
  
  <p>So I'm all confused now. Correct any misunderstandings... </p>
  
  <p>bind(ip address you want to listen to, port you want to listen to)</p>
  
  <p>sendto(message, ip address you want to send to, port you want to send to)</p>
  
  <p>0.0.0.0 is listening to everything. </p>
  
  <p>192.0.0.1 is listening to the router. </p>
  
  <p>127.0.0.1 is listening to just the computer. </p>
  
  <p>If so what ip address do I need to sendto to avoid an errno 22 and successfully send the message to the server? Or am I missing something with the sockets? </p>