title: Using UDP between remote server and client
body: <p>I am currently working on a project that needs a UDP communication between a server Amazon Frankfurt) and several hosts (Arduino). I need to be able to send JSON data from server to a host over UDP and it needs to work in real time (time is a real constraint here). Also, periodically a host will speak to server to inform server about its status. </p>
  
  <p>The problem I'm facing is that although I can ping the server, when I create the UDP socket with a port, I get this error (for any port):</p>
  
  <blockquote>
    <p>errno99: cannot assign requested address</p>
  </blockquote>
  
  <p>I also believe that since the hosts are in different countries, I can only get router's IP. Hosts will be given to users therefore it is impossible to alter user's router by hand. I need to use something that can handle these by code.</p>
  
  <p>I have been searching on <strong>Hole Punching</strong> and other techniques. I cannot decide what suits more to my scenario here. Sorry for my lack of network information, any help or guidance as "read or search these techniques" are appreciated. </p>
  
  <p>This code runs on server:</p>
  
  <pre><code> import socket
   import time
   #Host's public IP
   UDP_IP_ADDRESS = "178.243.98.86"
   UDP_PORT_NO = 13000
   Destination = (UDP_IP_ADDRESS,UDP_PORT_NO)
   Message = "Hello, Server"
   senderSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   while True:
       senderSock.sendto(Message, Destination)
       time.sleep(1);
  </code></pre>
  
  <p>And this code runs on my machine:</p>
  
  <pre><code> import socket
   #Server's public IP
   UDP_IP_ADDRESS = "172.31.46.111"
   UDP_PORT_NO = 13000
   recieverSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
   recieverSock.bind((UDP_IP_ADDRESS, UDP_PORT_NO))
   while True:
       data, addr = recieverSock.recvfrom(1024)
       print "Message: ", data
  </code></pre>