title: Is it possible to have a socket listening to two UDP IPs, one that is 127.0.0.1 (same machine) and a different computer at the same time?
body: <p>An eye-tracking application I use utilizes UDP to send packets of data. I made a python socket on the same computer to listen and dump the data into a .txt file. I already have this much working. </p>
  
  <p>A separate application also written in python (what the eye-tracked subject is seeing) is running on a separate computer. Because the eye-tracking application is continuous and sends unnecessary data, so far I've had to manually parse out the instances when the subject is looking at desired stimuli. I did this based on a manually synchronized start of both the stimuli and eye-tracking applications and then digging through the log file. </p>
  
  <p>What I want to do is have the second computer act as a second UDP client, sending a packet of data to the socket on the eye-tracking computer everytime the subject is looking at stimuli (where a marker is inserted into the .txt file previously mentioned). Is it possible to have a socket listening to two IP addresses at one time? </p>
  
  <p>Here's my socket script:</p>
  
  <pre><code>#GT Pocket client program
  
  import datetime
  import socket
  now = datetime.datetime.now()
  filename = 'C:\gazelog_' + now.strftime("%Y_%m_%d_%H_%M") + '.txt'
  
  UDP_IP = '127.0.0.1' # The remote host (in this case our local computer)
  UDP_PORT = 6666 # The same port as used by the GT server by default
  
  sock = socket.socket(socket.AF_INET, #internet
                                  socket.SOCK_DGRAM) #UDP 
  
  sock.bind( (UDP_IP, UDP_PORT) )
  
  while True:
      data, addr = sock.recvfrom( 1024) #I assume buffer size is 1024 bytes.
      print "Received Message:", data
      with open(filename, "a") as myfile:
      myfile.write(str(data + "\n"))
  
  sock.close()
  myfile.close()
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>@abarnert I was able to bind to the host address on the Ethernet interface and send a message from computer B to computer A, but computer A was no long able to receive packets from itself. When I specified <code>UDP_IP = '0.0.0.0'</code> computer B was no longer able to send data across the Ethernet. When I specified <code>UDP_IP = ''</code> I received the <code>`error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted</code> </p>
  
  <p>This have to do with the script I used on the Computer B to send the data:</p>
  
  <pre><code>import socket
  
  UDP_IP = "169.254.35.231" # this was the host address I was able to send through.
  UDP_PORT = 6666
  MESSAGE = "Start"
  
  print ("UDP target IP:"), UDP_IP
  print ("UDP target port:"), UDP_PORT
  print ("message:"), MESSAGE
  
  sock = socket.socket(socket.AF_INET,
                   socket.SOCK_DGRAM) 
  sock.sendto(MESSAGE, (UDP_IP, UDP_PORT) )
  </code></pre>
  
  <p>I didn't know where (or if at all) I needed to specify INADDR_ANY, so I didn't. But I did try once where <code>import socket.INADDR_ANY</code> but got <code>ImportError: No module named INADDR_ANY</code></p>
  
  <p>Seems like a simple issue based on your response, so I'm not sure where I'm messing up. </p>
  
  <p>EDIT2: I just reread your answer again and understand why socket.INADDR_ANY doesn't work. Please disregard that part of my previous edit</p>
  
  <p>EDIT3: Okay so the reason that I wasn't picking up data when specifying the host IP was that the application I was collecting data from on Computer A was still specified to send to 127.0.0.1. So I figured it out. I am still curious why 0.0.0.0 didn't work though!</p>